async def on_member_update(before, after):
a = ['Роль 1:', 'Роль 2']
if len(before.roles) < len(after.roles):
for i in after.roles:
if not i in before.roles:
if i.name in a:
role1 = client.guild.get_role(int('id'))
role1role = "\n".join([(member.mention) for member in role1.members])
embed_player.add_field(name=f'Роль1:\n', value=f'{role1role}' or 'отсутствует', inline=False)
await client.send(embed=embed_player)
删除人类角色时,机器人会抛出错误:
role1 = client.guild.get_role(int('id')) AttributeError: 'Bot' object has no attribute 'guild'
bot 根本没有公会,也就是说它有很多公会,你需要绑定到一个只有 1 个公会的对象,例如,绑定到一个人,
before.member.channel
或before.channel
或before.roles.channel
。