Can#39;t get discord.py to raise an error if user doesn#39;t have permissions to kick(如果用户无权踢球,则无法让 discord.py 引发错误)
问题描述
我正在尝试制作一个可以踢人的快速机器人,如果它有权这样做并且用户有权这样做,并且如果机器人没有权限或用户.但是我目前的解决方案似乎不起作用.这是处理它的代码,当您拥有权限时,该代码可以踢人,但如果机器人或用户没有权限,则不会引发错误.
I'm trying to make a quick bot that can kick people if it has the permission to do so and the user has the permission to do so as well as raise an error in chat if either the bot doesn't have the permissions or the user. However my current solution doesn't seem to be working. Here is the code that handles it, the code works to kick people when you have the permissions but doesn't raise an error if the bot or the user doesn't have the permissions.
@client.command(name = 'kick', pass_context = True)
@has_permissions(kick_members = True)
@bot_has_permissions(kick_members = True)
async def _kick(ctx, member : discord.Member, *, reason='No Reason Given'):
await member.kick(reason = reason)
await ctx.send(f'{member} was kicked for {reason}')
@_kick.error
async def kick_error(error, ctx):
if isinstance(error, MissingPermissions):
text = (f'Sorry {ctx.message.author}, you do not have permission to do that')
await ctx.send(text)
推荐答案
试试这样的:
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send("You do not have the permissions required for this command.")
return
raise error
这篇关于如果用户无权踢球,则无法让 discord.py 引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如果用户无权踢球,则无法让 discord.py 引发错误
基础教程推荐
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 求两个直方图的卷积 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 包装空间模型 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
