我正在尝试创建一个系统,在该系统中,它从服务器中获取一个没有在线角色的随机在线成员,并且从颜色中获取一个随机角色,并将其分配给该随机成员。但我不断收到此错误:
RuntimeWarning:从未等待协程'Member.add_roles'
member.add_roles(randomuser,randomcolors)运行时警告:启用 tracemalloc获取对象分配回溯
@client.command(name="sortearcolor")
@commands.has_any_role("DUEÑOS", "CO-OWNER", "Admin", "ADMIN", "Dev Discord+", "MOD", "MOD+", "Trial MOD", "Dev Discord")
async def _sorteocolor(ctx):
online = []
colors = ["Negro (Personalizado)", "Rosa (Ultra)", "Rosa-1 (Personalizado)",
"Rosa-2 (Personalizado)", "Violeta (Ultra)", "Violeta (Personalizado)",
"Morado (Personalizado)", "Celeste(Perso.)", "Violeta Brillante (Personalizado)",
"Aqua (Personalizado)", "Amarillo-1 (Personalizado)", "Amarillo (Personalizado)",
"Celesroide (Personalizado)", "Celeste (Personalizado)",
"Azul-1 (Personalizado)", "Azul (Personalizado)", "Azul (Generico)",
"Morado (Personalizado)", "Rosa pastel"]
mods = ["Admin", "ADMIN", "Dev Discord+", "MOD", "MOD+", "Trial MOD", "Dev Discord"]
for member in client.get_all_members():
if str(member.status) == "online":
for roles in ctx.guild.roles:
if roles.name in mods:
pass
else:
online.append(str(member))
randomuser = random.choice(online)
randomcolors = random.choice(colors)
member.add_roles(randomuser, randomcolors)
await ctx.send(f"User: **{randomuser}**, Role: **{randomcolors}**")
它发送消息user:user,role:role,但是没有给用户角色,我想这与我收到的错误消息有关。此外,它仍然会选择具有mod角色的成员,不确定原因。
答案 0 :(得分:0)
在discord.py中,必须先使用client-secret-key
,然后才能执行“操作”命令。就像您将消息发送到频道时使用await
一样,您也必须await
添加角色。尝试做,await