簡體   English   中英

我怎樣才能使它只有具有特定角色的成員才能執行命令?

[英]How can I make it so only members with a specific role can execute a command?

我的問題可能看起來很常見,但這次有一個轉折點。 我需要它來要求一個角色和一個特定角色,而不僅僅是少數幾個角色之一。 這是我嘗試過但不起作用的代碼

@bot.command()
@commands.has_any_role("Buffalo Bills")
@commands.has_any_role("Franchise Owner", "General Manager", "Head Coach", "Assistant Coach")

然后從那里,我命令的 rest。

所以這是你可以做到的一種方法。 使用@commands.has_role()@commands.has_any_role ,您可以確保用戶具有一個特定角色以及給定的角色之一。

@client.command()
@commands.has_role('Must Have Role')
@commands.has_any_role('Role One', 'Role Two')
async def role_test(ctx):
    await ctx.send("Hey this worked") 
# This would only send if the user has 'Must Have Role' and either 'Role One' or 'Role Two'

工作圖像

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM