【发布时间】:2019-10-28 01:17:53
【问题描述】:
我最近使用 discord.py 制作了一个不和谐机器人。我尝试为某些命令设置权限。我有这个测试命令功能:
@client.command()
@commands.has_role('Moderator')
async def cool(ctx):
await ctx.send("You are cool indeed!")
当用户没有“版主”角色时如何返回消息(错误)?
我已经试过了:
async def on_command_error(ctx, error):
if isinstance(error, commands.NoPrivateMessage):
await ctx.send("*Private messages.* ")
elif isinstance(error, commands.MissingRequiredArgument):
await ctx.send("*Command is missing an argument:* ")
elif isinstance(error, commands.DisabledCommand):
await ctx.send("*This command is currenlty disabled. Please try again later.* ")
elif isinstance(error, commands.CheckFailure):
await ctx.send("*You do not have the permissions to do this.* ")
elif isinstance(error, commands.CommandNotFound):
await ctx.send("*This command is not listed in my dictionary.*")
但我没有从中得到任何回报。
【问题讨论】:
标签: python error-handling bots discord discord.py