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

元气小坏坏 提交于 2019-11-29 08:33:44
Tim

To get it to work I changed your send_message line to await client.send_message(message.channel, 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'):
        embed = discord.Embed(title="Tile", description="Desc", color=0x00ff00)
        embed.add_field(name="Field1", value="hi", inline=False)
        embed.add_field(name="Field2", value="hi2", inline=False)
        await client.send_message(message.channel, embed=embed)

I used the discord.py docs to help find this. http://discordpy.readthedocs.io/en/latest/api.html#discord.Client.send_message for the layout of the send_message

http://discordpy.readthedocs.io/en/latest/api.html#embed for the API details

khazhyk

When executing this code, I get the error that 'Embed' is not a valid member of the module 'discord'. All websites, show me this code, and I have no idea of any other way to send a embed.

This means you're out of date. Use pip to update your version of the library.

pip install --upgrade discord.py
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!