简体   繁体   中英

Discord.py embed color

Hey there I'm using a script to post from one server to another embed, but I need to change the colour from the forwarded embed (output) in this part from the code you also change the footer and all so I assume I have to set there the embed colour. I tried already a lot of methods like:

embed=discord.Embed(color=0xd10a07)

 if message.channel.id in channels_forward_embed:
            dest_channel_id = channels_forward_embed[message.channel.id]
            if message.embeds:
                embed = message.embeds[0]


                embed.set_footer(text="TEST | TEST", icon_url="pictureurl")
            else:
                return

            try:
                await self.cog.send_embed(dest_channel_id, embed)
            except:
                print('Error sending embed')
    ```

https://discordpy.readthedocs.io/en/latest/api.html?highlight=embed#discord.Embed.colour

The colour code of the embed. Aliased to color as well. This can be set during initialisation.

The embed color can only be set during initialisation. You cannot change the embed color after.

embed = message.embeds[0]

Here you are copying an embed from an existing embed. You then call set_footer . There is no equivalent command like set_color .

What you have to do is:

embed_dict = message.embeds[0].to_dict()
embed_dict['colour'] = 0xd10a07
embed = discord.Embed.from_dict(**embed_dict)
embed.set_footer(text="TEST | TEST", icon_url="pictureurl")

This initializes a new embed with the exact same title, description etc but with a modified color.

Note: I can not test it yet. No guarantee that my code is working but the concept of it should be working. Let me know if it works. If it is not working do a print(embed_dict) it should have a color set somewhere which you need to overwrite with a new value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM