3
votes

My on_member_join doesnt seem to work. I wanted my bot to say out the names of the members that joined the sever but it doesnt detect if someone has joined or left.

import discord
from discord.ext import commands

client = commands.Bot(command_prefix = '.')

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

@client.event
async def on_member_join(member):
    print(f'{member.name} has joined this server')

@client.event
async def on_member_remove(member):
    print(f'{member}was removed')

client.run('*************************')

It is printing "bot is ready" on the terminal so the bot is working. But isn't detecting members leaving or joining pls help.

2
The bot has to be in the server, to detect new people joining. Already joined people arent detected. - Deru
@Deru it is already in a server n I have tried removing my second account n adding it back in but still it doesn't print that on the terminal - lushain
Also no errors? - Deru
@Deru nope no errors - lushain

2 Answers

2
votes

You're probably using discord python 1.5.0 or above, it's a common error, you just need Intents. If there's a error, you are supposed to read it, it will redirect you to your bot in the discord dev portal, there you can activate the privileged gateway intents check this out

And add this to your code

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

client = commands.Bot(command_prefix='.', intents=intents)
-2
votes

i solved this problem to downgrade discord.py

maybe intents option is error.

i'm already using discord api forum intents option but not working

so if u wanna on_member_join and remove events, downgrade your discord.py under version 1.5.0

u type this in console

pip install discord.py==1.4.2

and in your cords remove all about intents cord and activate your cords

that's it.