[英]Discord.py how can I test if a member has certain role in a dictionary of roles?
AdminRoles = ["Moderation","Administration","Emperor"]
@client.command()
async def Commands(ctx):
member = ctx.author
if AdminRoles in member.roles:
ShowCommand = discord.Embed(
title = "Moderation Commands",
description = "All commands",
colour = discord.Colour.red()
)
await ctx.send(embed = ShowCommand)
else:
ShowCommand = discord.Embed(
title = "Member Commands",
description = "All commands",
colour = discord.Colour.red()
)
await ctx.send(embed = ShowCommand)
我確實修復了上面的代碼,因為當我輸入命令時,它會一直顯示正常的播放器命令,並且假設會顯示 Mod 命令。
您正在查看列表AdminRoles
是否在 member.roles 中,整個列表為:
if ["a","b","m"] in members.roles:
但是您希望 AdminRoles 中的項目之一在 members.role 中,因此您需要以下內容:
test = [e for e in AdminRoles if e in members.roles]
if len(test) > 0:
doTheRightModeratorThing()
else:
doTheRightCommonerThing()
(最后一次檢查 adminRoles 中是否至少有一個角色在 member.roles 中)
在您的代碼中, if AdminRoles in member.roles:
。 這意味着 if 成員擁有所有AdminRoles
。 所以你可以像這樣改變你的代碼:
AdminRoles = ["Moderation","Administration","Emperor"]
@client.command()
async def Commands(ctx):
member = ctx.author
for role in member.roles:
if role.name in AdminRoles:
ShowCommand = discord.Embed(
title = "Moderation Commands",
description = "All commands",
colour = discord.Colour.red()
)
await ctx.send(embed = ShowCommand)
return
ShowCommand = discord.Embed(
title = "Member Commands",
description = "All commands",
colour = discord.Colour.red()
)
await ctx.send(embed = ShowCommand)
在此代碼中,如果成員具有任何AdminRoles
,則將發送審核命令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.