0
votes

I'm coding a simple discord bot and I want to make it so that the bot sends a greeting message when it joins the server

@client.event
async def on_guild_join(guild):
    general = find(lambda x: x.name == 'general',  guild.text_channels)
    if general and general.permissions_for(guild.me).send_messages:
        await general.send('Thanks for inviting me.'.format(guild.name))

However, this code only sends the message in general and if the general channel isn't named "general", it won't send. So now I want it to send the message in the System Messages Channel. How would I do this?

1
You kinda cant, let me explain. Discord System Messages Channel is only for community servers, also discord allows servers to change the name of that channel so even if you did set it to moderator-only which I think is the default name, it would not send if the following: Missing Permissions, or the channel name is different. Hope you understand, and if anyone does come up with an answer for this then maybe I am wrong. - GarrettSucksAtCode
@GarrettSucksAtCode I went in my server and checked, i might be wrong but if you go to server settings > Overview > System Messages Channel, you can select what channel for the system messages. So does this mean I can pass it in or not? - ChezStix

1 Answers

0
votes

You should use Guild.system_channel but in some cases it can be None as if the server has removed system channels

Below is the revised code:

@client.event
async def on_guild_join(guild):
    if guild.system_channel: # If it is not None
        await guild.system_channel.send(f'Thanks for inviting me to {guild.name}')