Search code examples
pythondiscord.pyembedemoji

Discord Bot Embed Custom Emoji


I'm creating a python discord bot which will output messages in an embed format.

I have added a few custom emoji's to the discord server and would like to use these in the embed message.

I would like it to look something like this https://i.sstatic.net/OdgdA.jpg except the emoji's used will be custom emojis NOT the discord default emojis.

I also want the emoji to sit the 'description' field. The custom emoji works fine in the title but won't work in 'description'.

 embed = discord.Embed(title="Here is the **title**! <:emoji1:52342365738338334>", color=0x24045b, description="Here is the emoji again! <:emoji1:52342365738338334>"

Solution

  • It's easiest to get the Emoji object that represents your custom emoji, then use that to build your strings

    from discord.utils import get
    
    @bot.command(pass_context=True)
    async def respond(ctx):
        emoji = get(ctx.message.server.emojis, name="emoji1")
        embed = Embed(title=f"Here is the **title**! {emoji}", color=0x24045b, description=f"Here is the emoji again! {emoji}")
        await bot.say(embed=embed)
    

    Here's a debugging command that you can use to get information about your Emoji

    from discord import Embed, Emoji
    from discord.ext.commands import Bot
    
    bot = Bot(command_prefix='!')
    
    @bot.command(pass_context=True)
    async def debug(ctx, emoji: Emoji):
        embed = Embed(description=f"emoji: {emoji}", title=f"emoji: {emoji}")
        embed.add_field(name="id", value=repr(emoji.id))
        embed.add_field(name="name", value=repr(emoji.name))
        await bot.say(embed=embed)
    
    bot.run("token")
    

    Call this from discord with !debug :emojiname:, and it should give you the information about that emoji. If it doesn't, then you may be trying to use an emoji that doesn't exist, or that your bot can't see (generally the emoji has to be from the server the command is invoked in/the response is being posted to)