本文介紹了如果用戶無權踢球,則無法讓 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 引發錯誤的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!