Reputation: 77
import discord
intent=discord.Intents.default()
intent.members=True
client=discord.Client()
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_member_join(member):
guild=client.get_guild(ServerID)
channel=guild.get_channel(ChannelID)
await channel.send(f'Welcome to the server{member.mention}! :D')
await member.send(f'Welcome to the {guild.name} server,{member.name}! :D')
print(f'Welcome to the {guild.name} server,{member.name}! :D')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
Why is my join function not being executed when someone joins my discord server ? i have given all the permission as well that is needed to msg in the specific channel but it seems that it never even calls the function Edit: I changed it to on_member_join it still doesn't work
Upvotes: 0
Views: 186
Reputation: 239
Your code for creating your client isn't complete. You have to assign the intents along with it, such as down below.
client=discord.Client(intents = intent)
In fact, I would recommend you look at the bot part of the discord.py documentation in order to setup the client with the necessary attributes for a discord bot.
(Also I'm going to assume you have the variables of ServerID and ChannelID saved somewhere else in the code, I just wanted to help the issue of triggering the on_member_join at all).
Upvotes: 2
Reputation: 140
join
is an invalid event listener name in discord.py
. Try changing the function's name to on_member_join
.
Upvotes: 1