Discord bot fails to detect user activity and appears as online only

I am a beginner in Python and have always wanted to create a Discord bot. Now that I’m attempting to build one, it’s not functioning as expected. Could anyone assist me in identifying the issues?

import discord

bot = discord.Client(intents=discord.Intents.default())

@bot.event
async def on_ready():
    print("Bot is ready!")

@bot.event
async def on_message(msg):
    if msg.content == "Hello":
        await msg.channel.send("Hi there!")

@bot.event
async def on_user_update(old_user, new_user):
    if new_user.activity:
        if str(new_user.activity) == 'League of Legends':
            await new_user.send("Please turn off League!")
        elif isinstance(new_user.activity, discord.Spotify):
            await new_user.send("Enjoying some good music?")
            with open('music.gif', 'rb') as music_file:
                await new_user.send(file=discord.File(music_file, 'music.gif'))

bot.run('your_token_here')

One potential issue might be with the use of await new_user.send() in the on_user_update event. This event does not have permission by default to send messages to users unless special intents are added. The primary intent for user status and activities is discord.Intents.members, which you need to enable while initializing your bot.

Try adding intents.members = True before creating the bot instance. Additionally, ensure your bot has the necessary permissions to send direct messages. Double-check the privacy settings of the users you’re trying to send messages to, as they may prevent DMs from bots.

Another thing to look at is whether the bot is actually detecting presence updates. This can happen if you haven’t enabled the necessary intents. You need to enable the discord.Intents.presences in addition to discord.Intents.members. Without these, your bot won’t be able to track user activities or status changes.

Here’s how you can enable those intents:

intents = discord.Intents.default()
intents.members = True
intents.presences = True
bot = discord.Client(intents=intents)

This should help your bot detect user activity changes correctly. Also, ensure that your bot’s role on your Discord server has permission to view member statuses or activity.