如何为所有用户添加多个角色?我编写的代码不会产生任何错误,但是它不起作用。我试图遍历不和谐公会的所有成员,然后将指定的角色添加到每个成员。
member = message.author
cat1 = discord.utils.get(member.guild.roles, id=767162794125557760)
cat2 = discord.utils.get(member.guild.roles, id=767159884314574888)
cat3 = discord.utils.get(member.guild.roles, id=767160508637642793)
cat4 = discord.utils.get(member.guild.roles, id=767159426565013504)
cat5 = discord.utils.get(member.guild.roles, id=767159149040500807)
if message.content.startswith('!addroles'):
if message.author.id == 80760379319259136:
for person in message.guild.members:
await person.add_roles(cat1, cat2, cat3, cat4, cat5)
print("done.")
答案 0 :(得分:0)
该代码对我而言完全正常:
@client.command()
async def addroles(message):
member = message.author
cat1 = discord.utils.get(member.guild.roles, id=767658943442583573)
cat2 = discord.utils.get(member.guild.roles, id=767658997607170069)
for person in message.guild.members:
await person.remove_roles(cat1, cat2)
print(person)
print("done.")
尝试打印出for循环中的每个人。可能是因为您的陈述被证明是错误的,例如提供了错误的作者ID,因此不会执行for循环。
也尝试使用命令而不是检查消息内容:
client = commands.Bot(command_prefix="!")
@client.command()
async def addroles(message):
pass