0
votes

I'm currently making a discord bot and would like to send a message in the #general channel of a server when it joins, this is the code that I have so far.

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:
        embed=discord.Embed(title="**======== *Thanks For Adding Me!* ========**", description=f"""
        Thanks for adding me to {guild.name}!
        You can use the `--help` command to get started!
        """, color=0xd89522)
        await general.send(embed=embed)

When i run this code noting happens. I dont get any erorrs or output.

If anyone could help, that would be awesome. Thanks!

1
Does this answer your question? Send a message when the bot joins a serverExtraFishness

1 Answers

0
votes

Does your on_guild_join have the event decorator (@client.event)? When I test your code with this decorator it works fine.

@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:
        embed=discord.Embed(title="**======== *Thanks For Adding Me!* ========**", description=f"""
        Thanks for adding me to {guild.name}!
        You can use the `--help` command to get started!
        """, color=0xd89522)
        await general.send(embed=embed)

In addition, you may want to have a fallback in case the guild your bot joins does not have a channel named "general". It may be more reliable to send a message in guild.text_channels[0], which will send the message in the first channel, or guild.system_channel to send a message in the system channel.