本文介紹了檢查用戶是否在 discord.py 中具有權限的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在為我的 discord.py 機器人創建一個踢命令.以下是 kick 命令可能的一些代碼:
I am making a kick command for my discord.py bot. Here is some code that the kick command might be:
async kick_command(self, ctx, userName: discord.User):
prefix_used = ctx.prefix
alias_used = ctx.invoked_with
text = msg[len(prefix_used) + len(alias_used):]
if discord.User permissions = "admin":
try:
kick(User)
except Exception as e:
ee = "Error: " + e
await ctx.send_message(content=ee)
我很確定 if 語句和 kick(User)
是無效的語法.你能幫幫我嗎?
I am pretty sure the if statement and kick(User)
are invalid syntax. Can you help me?
我的代碼:點擊這里
推薦答案
試試這個:
@bot.command()
@has_permissions(kick_members=True)
async def kick(self, ctx, Member: discord.Member):
await bot.kick(Member)
@kick.error
async def kick_error(error, ctx):
if isinstance(error, MissingPermissions):
await ctx.send("You don't have permission to do that!")
別忘了導入 has_permissions
:from discord.ext.commands import has_permissions
這篇關于檢查用戶是否在 discord.py 中具有權限的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!