[英]Trying to do an error message of missing required permission for discord bot on python
I am making an discord bot on python, and I don't wanna that regular users used the moderation commands.我正在 python 上制作 discord 机器人,我不希望普通用户使用审核命令。 I know how to do a check for permissions, @commands.has_permissions(kick_members=True)
, but I don't know how to do an error message of missing required permissions.我知道如何检查权限@commands.has_permissions(kick_members=True)
,但我不知道如何处理缺少所需权限的错误消息。 I tried that:我试过了:
@kick.error
async def kick_error(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send(':redTick: You don\'t have permission to kick members.')
I found that on Stack Overflow我在 Stack Overflow 上发现了
But in the cmd it says that: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: kick_error() missing 1 required positional argument: 'error'
但是在 cmd 中它说: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: kick_error() missing 1 required positional argument: 'error'
And if I swapped 'ctx' and 'error', like async def kick_error(self, error, ctx):
, it says the same thing, only instead of missing 1 required positional argument: 'error'
he wrote missing 1 required positional argument: 'ctx'
如果我交换 'ctx' 和 'error',比如async def kick_error(self, error, ctx):
,它说的是同样的事情,只是没有missing 1 required positional argument: 'error'
他写了missing 1 required positional argument: 'ctx'
How can I fix it?我该如何解决? And is there another way to do it?还有另一种方法吗?
You need to check if the error is instance of commands.MissingRequiredArgument
您需要检查错误是否是commands.MissingRequiredArgument
的实例
Seeing the error I assume that you are not in a cog, so remove self
看到错误我认为您不在齿轮中,因此请删除self
@kick.error
async def kick_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send(':redTick: You don\'t have permission to kick members.')
elif isinstance(error, commands.MissingRequiredArgument):
await ctx.send("Missing Argument")
else: raise(error) # for other errors so they dont get suppressed
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.