0
@bot.command(name="clear", alliases=["purge"])
@commands.has_permissions(manage_messages=True)
async def clear_messages(self, ctx, limit: typing.Optional[int] = 1):
    if 0 < limit <= 100:
        with ctx.channel.typing():
            await ctx.channel.purge(limit = limit)
            await ctx.message.delete()

I'm having issues with this code block specifically, where I get an error that 'str' has no attribut 'channel'. In other parts of my code (shown below) there is a similar idea, but the command passes. Any help is greatly appreciated.

@bot.command()
async def say(ctx, *args):
    await ctx.send('{}'.format(' '.join(args)))
    await ctx.message.delete()
2
  • 1
    Is this a method, or just a plain old function? If the latter, then you need to remove the self arg. Commented May 15, 2021 at 18:54
  • ctx is a parameter, so whatever is calling this function is passing a string. Commented May 15, 2021 at 19:05

2 Answers 2

2

There's two possible reasons:

  • Your clear_messages isn't in a class, in which case you should remove the self argument.
  • Your command is in a class, which would inply that you're using cogs. In this case, you should replace @bot.command to @commands.command

Judging by the code you gave, I'd say that the first reason may be the right one.

Sign up to request clarification or add additional context in comments.

1 Comment

the first one was a solution, i removed "self" and it worked, thanks so much!
0

thanks to @Mr_Spaar !

the issue was the "self" argument, i removed it and it worked perfectly!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.