AkIonSight
AkIonSight

Reputation: 385

discord.py on_member_join not working even though the bot is in the server and online

I have been trying to make a discord bot but I am facing problems with the on_member_join function. The bot has been given admin permissions and I face no error in the console either

Here is the code

import discord
intents = discord.Intents.default()
intents.members = True
client = discord.Client()

@client.event
async def on_ready():
    print(f'We have logged in as {client.user}')


@client.event
async def on_member_join(member):
    await member.send('welcome !')

client.run('TOKEN')

Upvotes: 0

Views: 1785

Answers (2)

user14445326
user14445326

Reputation: 5

Try using intents. With this version you will need to use intents.

https://discordpy.readthedocs.io/en/latest/api.html?highlight=intents#discord.Intents

Intents are the new features required in discord.py version 1.5.0 + If your bot doesn't use intents and you're using events such as on_member_join() it wont work!

import discord
from discord.ext import commands

intents = discord.Intents.all()
bot = commands.Bot(command_prefix='?', intents=intents)

Upvotes: 0

Just for fun
Just for fun

Reputation: 4225

You need to pass intents in the Client() initializer

Below is the revised code:

import discord
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)

@client.event
async def on_ready():
    print(f'We have logged in as {client.user}')


@client.event
async def on_member_join(member):
    await member.send('welcome !')

client.run('TOKEN')

Upvotes: 1

Related Questions