Z
Z
Zef1rok2021-03-28 22:14:49
Python
Zef1rok, 2021-03-28 22:14:49

How to make a message that the bot sends when connecting to the Discord.py server?

I'm making a bot and I can't figure out how to do it. Tell me who knows.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-03-28
@Zef1rok

on_guild_joincalled when the Client either creates a server or connects to an existing one.
The rest is to get all text channels, check if text channels exist at all, and send a message to the first one.

@bot.event
async def on_guild_join(guild):
    
    text_channels = guild.text_channels
    
    if text_channels:
        channel = text_channels[0]
    
    await channel.send('Привет, {}!'.format(guild.name))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question