Skip to content

How can I know who triggers on_member_update? #6182

Answered by ghost
riccardolunardi asked this question in Q&A
Discussion options

You must be logged in to vote

You can iterate through your server's audit log

Basically, since before and after are Member objects, you can get the guild from them:

@commands.Cog.listener()
async def on_member_update(self, before, after):
  async for entry in after.guild.audit_logs(limit=10):
      print('{0.user} did {0.action} to {0.target}'.format(entry))

I don't know if this is the best way to do that, but it works. Another way is to get the guild from a specific ID:

@commands.Cog.listener()
async def on_member_update(self, before, after):
  guild = self.bot.get_guild(123456789)
  async for entry in guild.audit_logs(limit=10):
      print('{0.user} did {0.action} to {0.target}'.format(entry))

Check out these refer…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@riccardolunardi
Comment options

@EvokerKing
Comment options

Answer selected by Rapptz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants