制作列表小写问题
Making lists lowercase issue
您好,我正在尝试让我在列表中的角色区分大小写,因此当调用命令 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 += ''
此行:
if Colours.lower() in roles:
正在尝试将列表 Colours
小写。你应该试试:
if role.lower() in roles:
因为 role
遍历颜色列表中的每个字符串。
一个python列表没有lower()
方法。请尝试:
for role in [c.lower() for c in Colours]:
if role in roles:
您好,我正在尝试让我在列表中的角色区分大小写,因此当调用命令 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 += ''
此行:
if Colours.lower() in roles:
正在尝试将列表 Colours
小写。你应该试试:
if role.lower() in roles:
因为 role
遍历颜色列表中的每个字符串。
一个python列表没有lower()
方法。请尝试:
for role in [c.lower() for c in Colours]:
if role in roles: