RaidingGames
RaidingGames

Reputation: 11

My discord bot will not send a welcome message, but is reading other messages. I am using discord.py

I am trying to create a basic discord bot and am currently trying to implement a welcome message. I am not getting an error message, it just doesn't do anything, and if I try and print a message to the console when a member joins, nothing happens. The on_message function works just fine, along with the on_ready.

#bot

import discord
TOKEN = ('top secret token')

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

@client.event
async def on_ready():
    print(f'{client.user} has connected to Discord!')

@client.event
async def on_message(message):
    if message.author == client.user:
        return
    if message.content.startswith('$hello'):
        await message.channel.send('Hello!')

@client.event
async def on_member_join(member):
    await message.channel.send('Welcome!')
    print('New User Detected')




client.run(TOKEN)

Upvotes: 0

Views: 783

Answers (1)

Harukomaze
Harukomaze

Reputation: 462

Let's see... hmm

does the bot know what message and channel are in the on_member_join event which has kwarg member. Nope, it doesn't!

message and channel aren't defined in an on_member_join. First, get the channel

channel = client.get_channel(ChannelID) this will get you the channel you want to send your message to. after that, we will simply use channel.send("message") to send the message.

The final code will look like this:

@client.event
async def on_member_join(member):
    channel = client.get_channel(ChannelID)
    await channel.send('Welcome!')
    print('New User Detected')

Upvotes: 2

Related Questions