Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I am creating the bot for my Discord server.

I have the new user's channel on my server. When a new user joins, I want to send the welcome message to this channel. But, I don't know how can I access the new users' channels.

@bot.event

async def on_member_join(member):

   What I should do here?

1 Answer

0 votes
by (36.8k points)

You can using the discord.utils.get or guild.get_channel. Then you can send the message by using the channel.send().

@bot.event

async def on_member_join(member):

    channel = discord.utils.get(member.guild.text_channels, name="the name of your channel in the bot will send message to")

    await channel.send('A new member joined.')

or

@bot.event

async def on_member_join(member):

    channel = member.guild.get_channel(channel id)

    await channel.send('A new member joined.')

 Want to be a master in Data Science? Enroll in this Data Scientist

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...