Home > Net >  Identify a userid within an on_presence_update in discord.py
Identify a userid within an on_presence_update in discord.py

Time:08-26

Hey everyone I'm working on a discord bot for fun using Discord.py and Im trying to identify when a certain user gets online, in the code below basically everything works except for the discord.User.id part which i can't get to work. How can i check the user/member within on_presence_update ? and if i can't could you suggest which method should i be using instead ? I tried using on_member_update at first but it doesn't include status change.

import discord
intents = discord.Intents.default()
intents.members = True
intents.presences = True

client = discord.Client(intents=intents)

@client.event
async def on_presence_update(before, after):
    if  discord.User.id == (userid) and str(after.status) == "online":
      
      channel = client.get_channel(channelid)
      await channel.send('hello')

client.run('token')

CodePudding user response:

before and after are both Member objects, which means you can access the User ID using before.id or after.id.

  • Related