我有一段代码,它具有指定的角色,并且该角色服务器将其放入列表中,并且列表中的所有角色都应更改颜色,但是....不会。< / p>
代码:
@client.command(pass_context=True,description="Linusifies a role")
@has_permissions(administrator = True)
async def rgb(ctx, role : discord.Role):
server = ctx.message.author.server
if (("{}, {}").format(server, role)) in rgb_list:
msg = "{}'s rgb is turned off :disappointed_relieved:".format(role)
rgb_list.remove(("{}, {}").format(server, role))
await client.send_message(ctx.message.channel, msg)
print (server)
else:
msg = "{}'s rgb has been turned on :christmas_tree:".format(role)
rgb_list.append(("{}, {}").format(server, role))
await client.send_message(ctx.message.channel, msg)
print (server)
并在我的@ client.event中:
async def rgb_():
await client.wait_until_ready()
while not client.is_closed:
print (rgb_list)
await client.edit_role(rgb_list,colour=discord.Colour(0x1abc9c))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0x11806a))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0x2ecc71))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0x1f8b4c))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0x3498db))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0x206694))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0x9b59b6))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0x71368a))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0xe91e63))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0xad1457))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0xf1c40f))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0xc27c0e))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0xe67e22))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0xa84300))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0xe74c3c))
await asyncio.sleep(2)
await client.edit_role(rgb_list,colour=discord.Colour(0x992d22))
await asyncio.sleep(2)
答案 0 :(得分:1)
阅读Client.edit_role
的文档。 readonly
使用edit_role
和Server
,而不是字符串列表。您应该将角色列表存储为Role
个中的list
个。然后,您可以遍历该对话框以更改颜色。
Role