我想删除成员在 if game_after
时拥有的所有角色
我如何在这里for role in member.roles: await member.remove_roles(role)
?
当我做404 Not Found (error code: 10011): Unknown Role
时我得到for role in member.roles: await member.remove_roles(role)
@commands.Cog.listener()
async def on_member_update(self, before, after):
game_after = [i for i in after.activities if str(i.type) == "ActivityType.playing"]
if game_after:
game_name = game_after[0].name.strip()
role = discord.utils.get(after.guild.roles, name=game_name)
await after.add_roles(role)
答案 0 :(得分:0)
问题是您试图删除everyone角色,所以idk如果这是您现在想要的但您可以配置它:
@commands.Cog.listener()
async def on_member_update(self, before, after):
game_after = [i for i in after.activities if str(i.type) == "ActivityType.playing"]
if game_after:
game_name = game_after[0].name.strip()
role = discord.utils.get(after.guild.roles, name=game_name)
roles = after.roles[1:]
await after.remove_role(*roles)