2021-02-28

Discord.py copy and paste channels command

    @commands.command()
    @commands.has_guild_permissions(administrator=True)
    async def copy(self, ctx):
        if str(ctx.author.id) not in Server.server_data:
            Server.server_data[str(ctx.author.id)] = Server.create_new_data()
        if str(ctx.author.id) in Server.server_data:
            Server.server_data[str(ctx.author.id)] = Server.create_new_data()
        
        channels = ctx.guild.text_channels
        Server.server_data[str(ctx.author.id)]["Channels"].append(str(channels))
        embed=discord.Embed(color=discord.Color.blue(), description = f"{ctx.guild.name}'s channels has been saved.")
        await ctx.send(embed=embed)

    @commands.command()
    @commands.has_guild_permissions(administrator=True)
    async def paste(self, ctx):
        embed=discord.Embed(color=discord.Color.blue(), description = "All channels have been pasted")
        channel = Server.server_data[str(ctx.author.id)]["Channels"]
        await ctx.guild.create_text_channel(channel)
        await ctx.send(embed=embed)

So I am trying to make a command for pasting the channels into a empty backup server but when do s!paste it sends an error message, which I tried to fix for a while but nothing is working.

Error <class 'discord.errors.HTTPException'>: 400 Bad Request (error code: 50035): Invalid Form Body
In name: Could not interpret "["[<TextChannel id=814160761068191817 name='general' position=0 nsfw=False news=False category_id=814160761068191815>, <TextChannel id=815038327610146866 name='false' position=1 nsfw=False news=False category_id=None>]"]" as string.
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/runner/Security-Bot/cogs/copy.py", line 28, in paste
    await ctx.guild.create_text_channel(channel)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/guild.py", line 929, in create_text_channel
    data = await self._create_channel(name, overwrites, ChannelType.text, category, reason=reason, **options)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 247, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In name: Could not interpret "["[<TextChannel id=814160761068191817 name='general' position=0 nsfw=False news=False category_id=814160761068191815>, <TextChannel id=815038327610146866 name='false' position=1 nsfw=False news=False category_id=None>]"]" as string.


from Recent Questions - Stack Overflow https://ift.tt/3r2lOwi
https://ift.tt/eA8V8J

No comments:

Post a Comment