Reputation: 385
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
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
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