@client.event
async def on_member_update(before, after):
if before.roles != after.roles:
channel = client.get_channel(729733881129074768)
emb = discord.Embed(title = '', description = f'**Обновление ролей пользователя - {before.mention}**', colour = discord.Color.red())
emb.add_field(name = '**Роли до**', value = [r.mention for r in before.roles] )
emb.add_field(name = '**Роли после**', value = [r.mention for r in after.roles] )
await channel.send(embed = emb)
@client.event
async def on_member_update(before, after):
if before.roles != after.roles:
channel = client.get_channel(729733881129074768)
emb = discord.Embed(description = f'**Обновление ролей пользователя - {before.mention}**', colour = discord.Color.red())
emb.add_field(name = '**Роли до**', value = ", ".join([r.mention for r in before.roles]))
emb.add_field(name = '**Роли после**', value = ", ".join([r.mention for r in after.roles]))
async for event in before.guild.audit_logs(limit=1, action=discord.AuditLogAction.member_role_update): # https://discordpy.readthedocs.io/en/v1.3.4/api.html#discord.AuditLogAction.member_role_update
# event: AuditLogEntry — https://discordpy.readthedocs.io/en/v1.3.4/api.html#discord.AuditLogEntry
if getattr(event.target, "id", None) != before.id:
# изменение ролей пользователя прошло без записи в логах аудита, или в лог аудита попала другая запись перед выполнением текущего участка кода
continue
emb.add_field(name="Изменённые роли", value = ", ".join([getattr(r, "mention", r.id) for r in event.before.roles or event.after.roles])) # event.before, event.after: AuditLogDiff — https://discordpy.readthedocs.io/en/v1.3.4/api.html#discord.AuditLogDiff
emb.add_field(name="Модератор", value = event.user)
break
await channel.send(embed = emb)
@commands.command(name = 'on_member_update')
async def hueta123(before, after):
if before.roles != after.roles:
channel = client.get_channel(729733881129074768)
emb = discord.Embed(title = '', description = f'**Обновление ролей пользователя - {before.mention}**', colour = discord.Color.red())
emb.add_field(name = '**Роли до**', value = [r.mention for r in before.roles] )
emb.add_field(name = '**Роли после**', value = [r.mention for r in after.roles] )
await channel.send(embed = emb)