14

How can I make my bot use my custom emoji in any discord server?

@bot.command(pass_context=True)
async def ping(ctx):
    msg = "Pong :CustomEmoji: {0.author.mention}".format(ctx.message)
    await bot.say(msg)

Example: If I upload some custom emojis on Server 1 and when we use the !ping command (mentioned above) in Server 2 or Server 3 or any server where the bot has access to, it should use the custom emoji.

Result: Pong with :CustomEmoji:

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
Demotry
  • 869
  • 4
  • 21
  • 40
  • See my answer [here](https://stackoverflow.com/questions/48982061/how-do-you-have-a-bot-add-a-reaction-using-a-custom-emoji) for an example of how to get custom emoji using their names. – Patrick Haugh Aug 23 '18 at 20:17
  • @PatrickHaugh your answer in that link is for adding reactions? – Demotry Aug 23 '18 at 20:28
  • Yes, but the relevant part was using the name of the emoji to get the `discord.Emoji` object. You can then pretty easily `"Pong {1}: {0.author.mention}".format(ctx.message, emoji)` – Patrick Haugh Aug 23 '18 at 20:30
  • @PatrickHaugh is there any option to get Emoji ID for animated ? – Demotry Aug 24 '18 at 11:13
  • Just write a command that takes an emoji: `@bot.command() async def getemoji(emoji: discord.Emoji): print(emoji.id)` – Patrick Haugh Aug 24 '18 at 11:20

5 Answers5

20

From https://github.com/Rapptz/discord.py/issues/390:

It's <:emoji_name:emoji_id> for custom emojis.

You can also find the discord.Emoji instance through Server.emojis and then cast it to str.

pppery
  • 3,731
  • 22
  • 33
  • 46
Danny
  • 822
  • 1
  • 9
  • 30
  • 5
    If you are lazy and want to get the formatted version of `<:emoji_name:emoji_id>` automatically for your emoji, go in Discord and open type in `\:YourEmoji:` (Be sure to replace "YourEmoji with the name of your emoji!) Discord will automatically return a formatted version of `<:emoji_name:emoji_id>` for your emoji. source: https://github.com/Rapptz/discord.py/issues/390#issuecomment-625929794 – Artem Bernatskyi Mar 29 '21 at 20:43
8

Also for animated ones you do <a:emoji_name:emoji_id>

Nick
  • 138,499
  • 22
  • 57
  • 95
user14391471
  • 81
  • 1
  • 1
1

First you need to add the Emoji to YOUR (on a server where the bot has access) server. after adding you type in the Emoji name e.g -> ":myemoji:" and before the emoji you type an backslash -> (backslah here):myemoji: and send the message. When you send the message, you can maby see something like this -> "<:bahn:874911228361854996>", you can use this direct in the bot message example: await ctx.send(" my custom emoji <:bahn:874911228361854996>")

Gustavolel
  • 11
  • 2
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 16 '23 at 20:16
0

As we know, every discord bot has nitro privileges when it comes to using emotes. So a bot can access any emoji for all servers it has been added to. What I do is make an API converter for myself with a global emote dictionary.

emojis=None

@bot.command(pass_context=True)
async def ping(ctx):
    global emojis
    if not emojis:
        emojis = {e.name:str(e) for e in ctx.bot.emojis}
    msg = "Pong :CustomEmoji: {0.author.mention}".format(ctx.message).replace(':CustomEmoji:',emojis['CustomEmoji'])
    await ctx.send(msg)
Arnab Santra
  • 101
  • 1
  • 3
0
@bot.event
async def on_reaction_add(reaction, user):

    if reaction.emoji.id == emoji_id:
        await reaction.message.delete()

IMPORTANT: Change the emoji_id, It deletes the message

rizzyh
  • 1
  • 1