0

I'm tweaking a discord bot I built with python and could use some help figuring out why this code is breaking. If a member of the server tries to call a command that is restricted to the roles Moderator and Hokage, I want the bot to send a message to the channel saying they do not have permission.

@client.command(description="Deletes a specific number of messages. If no amount is specified, 5 messages will be deleted.")
@commands.has_role('Moderator, Hokage')
async def purge(ctx, amount=5):
  if role == ('Moderator, Hokage'):
    await ctx.channel.purge(limit=amount)
  else:
    await ctx.send(f'You do not have permission to do that. ')
  • You need to pass the role names separately, you have them in one string: `@commands.has_role('Moderator', 'Hokage')`. You can also get rid of your `if`, the command will only run if they have one of those roles. – Patrick Haugh Oct 21 '19 at 20:02
  • The role permissions work fine, it just won't send a message if you don't have the roles listed. Also, has_role only takes one argument, so adding the extra apostrophes breaks the code. – CommanderPrompt Oct 21 '19 at 23:51
  • 1
    My fault, there's a separate decorator called [`has_any_role`](https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.has_any_role). For your other question, see this answer: https://stackoverflow.com/questions/54324466/check-if-user-has-a-certain-role – Patrick Haugh Oct 22 '19 at 02:44

0 Answers0