I've tried a lot of things but I just can't do it. How can my Discord bot send a message when a user is timed out?
This code and a lots of other codes:
if before.pending and not after.pending:
async for entry in after.guild.audit_logs(limit=1, action=discord.AuditLogAction.member_role_update):
if entry.target.id == after.id and discord.utils.get(entry.after.roles, name="Timeout") is None:
channel = bot.get_channel(1234567890)
await channel.send(f"{after.mention} wurde aus dem Timeout entfernt.")
elif not before.pending and after.pending:
async for entry in after.guild.audit_logs(limit=1, action=discord.AuditLogAction.member_role_update):
if entry.target.id == after.id and discord.utils.get(entry.before.roles, name="Timeout") is None:
channel = bot.get_channel(1234567890)
await channel.send(f"{after.mention} wurde in den Timeout versetzt.")
According to the docs, you can check if a
Member
is timed out by looking at the timed_out_until attribute.So, if you want to track when a member is timed out, you can use the on_member_update event and check if the new member it's timed out.