This is my code and I added error handling, but it's not working. I'm getting an error in bash when the command is executed by a non-admin. Below command if I type ?hello with admin role it works, but when a non-admin types that commands, they receive You don't have permission to use this command.
token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
prefix = "?"
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix=prefix)
bot.remove_command("help")
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.command(pass_context=True)
async def on_command_error(self, exception, ctx):
if isinstance(exception, CheckFailure):
print("{0} does not have permission to run `{1}`".format(ctx.message.author, ctx.command.name))
elif isinstance(exception, CommandNotFound):
# This is handled in CustomCommands
pass
else:
print(exception)
await self.on_error("on_command_error", exception, ctx)
@bot.command(pass_context=True)
@commands.has_any_role("Admin", "Moderator")
async def hello(ctx):
msg = 'Hello... {0.author.mention}'.format(ctx.message)
await bot.say(msg)
bot.run(token)
awaitkeyword, there. AFAICTawaitcan only appear inside async functions, andon_command_errorhasn't been marked as async. (posting this as a comment and not an answer because I don't know enough about async and/or discord to know whether this completely solves the problem)