Hey everyone! I’m having trouble with my Discord bot written in Python. The bot connects successfully and shows as online, but it’s not responding to member activity updates like I expected it to.
I want the bot to detect when users start playing specific games or listening to Spotify, but the on_member_update event doesn’t seem to trigger at all. The basic message commands work fine, but activity monitoring is completely broken.
Here’s my current code:
import discord
bot = discord.Client(intents=discord.Intents.default())
@bot.event
async def on_ready():
print("Bot is ready to work!")
@bot.event
async def on_message(msg):
if msg.content == "!test":
await msg.channel.send("Hello there!")
@bot.event
async def on_member_update(old_state, new_state):
if new_state.activity is not None:
if str(new_state.activity) == 'Valorant':
member = new_state
await member.send("Stop playing and go study!")
elif isinstance(new_state.activity, discord.Spotify):
member = new_state
await member.send("Nice music choice!")
with open('dance.gif', 'rb') as gif_file:
await member.send(file=discord.File(gif_file, 'dance.gif'))
bot.run('my_token_here')
What am I missing here? Any help would be appreciated!
Yeah, it’s definitely the intents issue, but there’s more to it. Even with presence intent enabled, you need to check activity types correctly. I had the same problem when I started with activity detection. Don’t compare str(new_state.activity) against ‘Valorant’ - the string representation changes. Use new_state.activity.name instead if it’s a Game activity. Your bot also needs to share servers with users you’re monitoring. It can’t detect activity changes for users in different guilds. And make sure your bot has proper permissions in those servers - even with correct intents, events won’t trigger without the right perms.
Hit this same problem last month building my guild activity tracker. The other answers nailed the intent issue, but here’s something that cost me hours - Discord’s activity detection is super inconsistent with newer games. Valorant works fine, but some games don’t register or have delays.
Your code will crash if someone runs multiple activities since you’re checking new_state.activity instead of new_state.activities (plural). The single version only grabs the first one.
Also add error handling for DMs - users might have them disabled from server members, which throws an exception and breaks your event handler.
you’re missing the presence intent! discord.Intents.default() doesn’t include presence data, so on_member_update won’t fire for activity changes. try intents = discord.Intents.default() then intents.presences = True and pass that to your Client constructor. also make sure you enabled the intent in the developer portal.