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?
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}')
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments