制作清单小写问题

时间:2019-03-22 12:50:58

标签: python-3.x discord discord.py discord.py-rewrite

嗨,我正尝试使列表中的角色区分大小写,以便在调用命令 Blue 时可以将其作为 Blue或blue 来调用我从我的代码中得到的是:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'list' object has no attribute 'lower'

发生错误的特定行if Colours.lower() in role:

这就是我的代码的样子。

#--- Role list Categories ---"
    Colours = ['blue', 'Yellow', 'Pink', 'Black']
    Games = ['LoL', 'WoW']
    Platforms = ['PC', 'Xbox', 'PS4', 'Nintendo Switch']

    if ctx.message.channel == intros:
        pass
    else:
        if ctx.message.channel == botroom:
            message = '\n**Colour Roles** \n__Change the colour of your nickname.__\n'.format(author.display_name)
            for role in Colours:
                if Colours.lower() in roles: # if the command is typed cases-sensitive 
                    message += '\n{} **({})**'.format(role, len([member for member in guild.members if ([r for r in member.roles if r.name == role])]))
                    message += ''

2 个答案:

答案 0 :(得分:1)

python列表没有lower()方法。请尝试:

for role in [c.lower() for c in Colours]:
    if role in roles:

答案 1 :(得分:0)

此行:

python3 20767 openwpm 971r FIFO 0,12 0t0 918673 pipe python3 20767 openwpm 972r FIFO 0,12 0t0 918674 pipe ….. python3 20767 openwpm 1015r FIFO 0,12 0t0 918717 pipe python3 20767 openwpm 1016r FIFO 0,12 0t0 918718 pipe python3 20767 openwpm 1017r FIFO 0,12 0t0 918719 pipe python3 20767 openwpm 1018r FIFO 0,12 0t0 918720 pipe python3 20767 openwpm 1019r FIFO 0,12 0t0 918721 pipe python3 20767 openwpm 1020r FIFO 0,12 0t0 918722 pipe python3 20767 openwpm 1021r FIFO 0,12 0t0 918723 pipe python3 20767 openwpm 1022r FIFO 0,12 0t0 918724 pipe

试图将列表if Colours.lower() in roles:小写。您应该尝试:

Colours

因为if role.lower() in roles:遍历了颜色列表中的每个字符串。