所以我想让我的机器人可以打印出某些操作缺少的权限。 这是我的代码:
@bot.event
async def on_command_error(ctx, error): #error commands handler
if isinstance(error, commands.BotMissingPermissions):
await ctx.send("Bot didn\'t has such a permissions")
#this line gonna print what are the missing permissions
@bot.command(pass_context = True)
@commands.bot_has_permissions(read_messages = True, manage_messages = True, read_message_history =
True)
async def purge(ctx, amount : int): #clear amount of messages
#do something
那我该如何打印缺少的权限?
答案 0 :(得分:1)
所以这段代码将打印所有必需的权限,不是,仅显示机器人没有的权限,但我认为它仍然很不错
@bot.event
async def on_command_error(ctx, error): #error commands handler
if isinstance(error, commands.BotMissingPermissions):
await ctx.send("Bot didn\'t has such a permissions")
await.ctx.send(f'{commands.BotMissingPermissions(["read_message",
"manage_messages", "read_message_history"])}') #this line gonna print what
are the required permissions
@bot.command(pass_context = True)
@commands.bot_has_permissions(read_messages = True, manage_messages = True,
read_message_history = True)
async def purge(ctx, amount : int): #clear amount of messages
#do something