Skip to content
Advertisement

I would like to make a discord bot that sends a message when a member goes online but I can’t seem to make it work ? (python)

I would like to make it so when a member goes online my both will send a message in the server welcoming the member but I cannot find a way to do so if I could get the name of the user too it would help thank you. Here is my code that is not working

Advertisement

Answer

Here’s a snippet that currently works

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

client = discord.Client(intents=intents)

@client.event
async def on_member_update(before, after):
    if after.status.name == 'online':
        await client.get_channel(id=`channel_id`).send('Hello')

client.run(`your_token`)

on_member_update

Called when a Member updates their profile.

This is called when one or more of the following things change:

  • status
  • activity
  • nickname
  • roles
  • pending

This requires Intents.members to be enabled.

You also need to allow presences to do what you really want

Whether guild presence related events are enabled.

This corresponds to the following events:

  • on_member_update() (activities, status)

And finally do what this answer mentions

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement