Discord.py "AttributeError: 'str' object has no attribute 'channel'"

255 views Asked by At

I haven't touched anything in my code it was working before now it isn't what do I do?

My Code:

  @commands.command(aliases=['Purge', "Clear", "clear"])
  @commands.has_permissions(manage_messages = True)
  async def purge(self,message,ctx,amount=2):
    LOG_CHANNEL = self.client.get_channel(898771125482455041)
    await ctx.channel.purge(limit=amount)
    await ctx.message.delete()
    await ctx.send(f":white_check_mark: Cleared `{amount}` Messages!")
    
    embed=nextcord.Embed(title="Messages Cleared", color=0xf2ec00)
    embed.add_field(name="Responsible Mod:", value=f"{ctx.author.name}", inline=False)
    embed.add_field(name="Channel:", value=f"{ctx.channel.mention}", inline=False)
    embed.add_field(name="Amount:", value=f"{amount}", inline=False)
    await LOG_CHANNEL.send(embed=embed)

The Error: AttributeError: 'str' object has no attribute 'channel'

1

There are 1 answers

0
moinierer3000 On BEST ANSWER

Your arguments are switched around, ctx needs to be the first argument, except in a class where it needs to be the second, after self. If you swap message and ctx around it should work.

async def purge(self, ctx, message, amount=2):

However, I'm not sure why you have a message argument in the first place, since you do not seem to use it anywhere. You can just delete it if you are not using it to avoid a missing argument error.

async def purge(self, ctx, amount=2):