![](/img/trans.png)
[英]Trying to do an error message of missing required permission for discord bot on python
[英]Trying To Convert a discord rename permission error to a default message when that error comes up, How Do I do That?
@rename.error
async def rename_error(ctx, error):
if isinstance(error, PermissionError):
await ctx.send("I don't have the permission to do that!¯\_(ツ)_/¯")
else:
raise error
這是我當前的代碼。 我想做的是讓我的機器人提出默認響應,而不是在我的控制台無權重命名某個管理員時告訴我在控制台中引發錯誤。 我對這個錯誤轉換完全陌生,我實際上復制並粘貼了它,但它仍然對我不起作用。 有人可以幫我嗎?
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
這是我試圖轉換為默認消息的錯誤。
您應該使用on_command_error
事件,它有兩個 arguments:
ctx
→ Context
objecterror
→ CommandError
異常(繼承自DiscordExeption
)如何使用它:
from discord.ext import commands
@bot.event #or client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandInvokeError) and "Missing Permissions" in str(error):
await ctx.send("I don't have the permission to do that!¯\_(ツ)_/¯")
else:
raise error
您會在此處找到每個 API 錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.