How do I use discord.py to send a greeting message in the System Messages Channel

ChezStix

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?

Poojan

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I send a message to a specific channel in discord.js?

From Dev

how can i make my discord.py bot send a message i choose to a channel i choose?

From Dev

How do I send a direct message to someone when they join a server with discord.py

From Java

How can I get a list of all the messages in a channel and then pick a random message from that list to send as a message?

From Dev

How to check if a channel has any messages? Discord.py

From Dev

How do I move a user to a specific channel on discord using the discord.py API

From Dev

How do I send a channel message using channel.trigger with websocket-rails gem

From Dev

How do i delete the previous messages that my discord bot sent in a specific channel?

From Java

discord.py (rewrite) How can I narrow a commands use ability to a single channel?

From Java

discord.py (rewrite) How do I make a command to a specific channel

From Dev

Discord.py, there is any method do edit a message send by a webhook?

From Dev

Discord.py bot.send_message() does not go to the channel it has been called at

From Dev

How can I check the role of a message author + How do I DM specific roles on Discord.py?

From Java

message.channel.id Discord PY

From Dev

Is TcpClient a single connection use? How do I send a second message?

From Dev

(discord.py) How to send content of a text file as a message

From Dev

Programming a Discord bot in Python- How do I make it automatically send messages?

From Dev

Discord py how can I join a voice channel

From Dev

How do I send an interpolated string on a channel?

From Dev

How do I send a message without using the deprecated way "sendMessage" in discord.js?

From Dev

pythonanywhere - How do I use websockets to transmit messages as per the web2py messaging example?

From Dev

pythonanywhere - How do I use websockets to transmit messages as per the web2py messaging example?

From Dev

How do I reply to a message outside of the channel I typed in?

From Dev

How do I change default notification settings for a Discord channel?

From Dev

How do I use Msg.exe to send messages on Windows 7?

From Dev

How can I disable greeting message when ssh in to a server?

From Dev

In discord.py, How do I use add_roles to add multiple roles to one person?

From Dev

How to send messages on a "side channel" in Spring XD?

From Dev

How do I send message programmatically in iPhone

Related Related

  1. 1

    How do I send a message to a specific channel in discord.js?

  2. 2

    how can i make my discord.py bot send a message i choose to a channel i choose?

  3. 3

    How do I send a direct message to someone when they join a server with discord.py

  4. 4

    How can I get a list of all the messages in a channel and then pick a random message from that list to send as a message?

  5. 5

    How to check if a channel has any messages? Discord.py

  6. 6

    How do I move a user to a specific channel on discord using the discord.py API

  7. 7

    How do I send a channel message using channel.trigger with websocket-rails gem

  8. 8

    How do i delete the previous messages that my discord bot sent in a specific channel?

  9. 9

    discord.py (rewrite) How can I narrow a commands use ability to a single channel?

  10. 10

    discord.py (rewrite) How do I make a command to a specific channel

  11. 11

    Discord.py, there is any method do edit a message send by a webhook?

  12. 12

    Discord.py bot.send_message() does not go to the channel it has been called at

  13. 13

    How can I check the role of a message author + How do I DM specific roles on Discord.py?

  14. 14

    message.channel.id Discord PY

  15. 15

    Is TcpClient a single connection use? How do I send a second message?

  16. 16

    (discord.py) How to send content of a text file as a message

  17. 17

    Programming a Discord bot in Python- How do I make it automatically send messages?

  18. 18

    Discord py how can I join a voice channel

  19. 19

    How do I send an interpolated string on a channel?

  20. 20

    How do I send a message without using the deprecated way "sendMessage" in discord.js?

  21. 21

    pythonanywhere - How do I use websockets to transmit messages as per the web2py messaging example?

  22. 22

    pythonanywhere - How do I use websockets to transmit messages as per the web2py messaging example?

  23. 23

    How do I reply to a message outside of the channel I typed in?

  24. 24

    How do I change default notification settings for a Discord channel?

  25. 25

    How do I use Msg.exe to send messages on Windows 7?

  26. 26

    How can I disable greeting message when ssh in to a server?

  27. 27

    In discord.py, How do I use add_roles to add multiple roles to one person?

  28. 28

    How to send messages on a "side channel" in Spring XD?

  29. 29

    How do I send message programmatically in iPhone

HotTag

Archive