rupam_das
rupam_das

Reputation: 60

Not sending in Welcome Message in Discord (using discord.py)

I am new to Python as well as StackOver flow. I am coding a Discord Bot for my Guild. I first feature I want to add was sending a Welcome Message in a Specific Channel. I coded it and when running I got no error...but when someone is joining my Server, no message was send by the bot.

Here's my code:

from discord.ext import commands
import discord

bot = commands.Bot(command_prefix='-')
TOKEN = '<Bot Token>'

@bot.event
async def on_ready():
print("Succesfully logged in as {0.user}".format(bot))

@bot.event
async def on_memeber_join(member):
try:
    channel = bot.get_channel(<Channel ID>)
    await channel.message.send(
        'Welcome to PRIME CLUB {0.mention}'.format(member))
except Exception as e:
    print(e)


bot.run(TOKEN)

Please Help me in correcting my Mistakes... Thanks in adavnce

Upvotes: 0

Views: 191

Answers (2)

rupam_das
rupam_das

Reputation: 60

Thx @stijndcl for the help.... Currently This script is working well for me..

@bot.event
async def on_member_join(member):
    for channel in member.guild.channels:
        if str(channel.id) == '<CHANNEL ID>':
            await channel.send(f'Welcome!! {member.mention}')

Upvotes: 0

stijndcl
stijndcl

Reputation: 5650

For on_member_join to work, you need to enable the Members Intent, both in your code and on your bot's dashboard. Info on how to do that is in the API Docs.

Also, you spelled member wrong ("memeber"). Your indentation looks wrong as well (1 tab when going inside of a function).

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

bot = commands.Bot(command_prefix='-', intents=intents)

@bot.event
async def on_ready():
    # Fix indentation
    print(...)

# Spell the name of the event correctly
@bot.event
async def on_member_join(member):
    # Fix indentation
    try:
        channel = ...

Upvotes: 1

Related Questions