How can I send an embed via my Discord bot, w/python?

To get it to work I changed your send_message line to
await message.channel.send(embed=embed)

Here is a full example bit of code to show how it all fits:

@client.event
async def on_message(message):
    if message.content.startswith('!hello'):
        embedVar = discord.Embed(title="Title", description="Desc", color=0x00ff00)
        embedVar.add_field(name="Field1", value="hi", inline=False)
        embedVar.add_field(name="Field2", value="hi2", inline=False)
        await message.channel.send(embed=embedVar)

I used the discord.py docs to help find this.
https://discordpy.readthedocs.io/en/latest/api.html#discord.TextChannel.send for the layout of the send method.

https://discordpy.readthedocs.io/en/latest/api.html#embed for the Embed class.

Before version 1.0: If you’re using a version before 1.0, use the method await client.send_message(message.channel, embed=embed) instead.

Leave a Comment