Search code examples
pythonembeddiscorddiscord.py

How can I edit an embed color with my discord bot with discord.py


I've been working on a discord bot for fun. I was wondering how I could use edit_message to change the embed color of the message.

Here is my code:

@bot.command()
async def test(self):
    """Embed color changing"""
    em1 = discord.Embed(title="Red", colour=0xFF0000)
    msg = await self.message.channel.send(embed=em1)
    em2 = discord.Embed(title="Green", colour=0x00FF00)
    await self.bot.edit_message(msg, embed=em2)

When I run the command I get this error:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Bot' object has no attribute 'edit_message'


Solution

  • Which version of discord.py are you using? Your code looks like it was written for v0.16 or older.

    After v1.0.0 you would use Message.edit()

    await msg.edit(embed=em2)