Obit
Obit

Reputation: 25

Discord.py (Rewrite) on_member_update not working properly

I have a question about the on_member_update function of the discord.py package. My Issue is that the on_member_update function only triggers when the bot itself is updated (like a role update) and not when an other user is updated (how it's supposed to work). Here is a breakdown of my Code:

import discord
from discord.ext import commands
import sys


TOKEN = 'myToken'
BOT_PREFIX = '!'



Intents = discord.Intents()
Intents.members = True
Intents.presences = True

bot = commands.Bot(command_prefix=BOT_PREFIX, Intents = Intents)

@bot.event
async def on_ready():
    print("Logged in as: " + bot.user.name + "\n")

@bot.event
async def on_member_update(before, after):
    if str(before.status) == "online":
        if str(after.status) == "offline":
            print("{} has gone {}.".format(after.name,after.status))
    else:
        print("lol")

@bot.command(pass_context=True)
async def stop(ctx):
    await ctx.author.send("bot stopped")
    sys.exit(0)

bot.run(TOKEN)

Hope you have an idea how to make it work. Thank you for your help!

Upvotes: 2

Views: 1932

Answers (2)

DeemonRider
DeemonRider

Reputation: 63

The accepted solution didn't work for me.

I needed to change:

on_member_update to on_presence_update according to the migration guide:

https://nextcord.readthedocs.io/en/latest/migrating_2.html

"on_presence_update() replaces on_member_update() for updates to Member.status and Member.activities."

Upvotes: 1

MoaiadFayez
MoaiadFayez

Reputation: 94

You should enable the presences intents for your bot from the developers portal like in the image below.

discord developer portal

https://i.sstatic.net/cAn8m.png

Upvotes: 1

Related Questions