0
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

4
  • I think discord python is discontinued ! Commented Nov 7, 2021 at 12:41
  • @httpanand idts cos i am onnly having issue with the join function rest all are working normally Commented Nov 7, 2021 at 13:04
  • 1
    Please read the docs for the library. The event isn't called "join". Commented Nov 7, 2021 at 13:10
  • @MohammadYusuf ok . my friends who were using it , migrated to JS as dpy is no more maintained . Read the docs for more info . Commented Nov 7, 2021 at 13:13

2 Answers 2

2

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).

Sign up to request clarification or add additional context in comments.

Comments

1

join is an invalid event listener name in discord.py. Try changing the function's name to on_member_join.

1 Comment

heyy i changed the thing it still doesn't work

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.