亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Discord.py 如何測試成員是否在角色字典中具有特定角色?

Discord.py 如何測試成員是否在角色字典中具有特定角色?

catspeake 2023-09-12 16:58:11
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 命令。
查看完整描述

2 回答

?
楊__羊羊

TA貢獻1943條經驗 獲得超7個贊

在您的代碼中,您做到了if AdminRoles in member.roles:。這意味著如果成員擁有所有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,則將發送審核命令。


查看完整回答
反對 回復 2023-09-12
?
收到一只叮咚

TA貢獻1821條經驗 獲得超5個贊

您正在查看列表是否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 中)


查看完整回答
反對 回復 2023-09-12
  • 2 回答
  • 0 關注
  • 144 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號