3
votes

I am trying to let my discord bot display the image file of emojis. So you post a emoji and the bot replies with an attached image of the emoji.

It's working for emojis of servers on which the bot is online. But how can i get the url of emojis from other servers?

I search for the emoji with bot.emojis.get But how can i search "outside" of the client "bot"? Or get the url on a different way?

My code for emojis from joined servers:

const emoji = bot.emojis.get(emojiID);

await message.channel.send({files: [
{
  attachment: emoji.url,
  name: emoji.name + '.png'
}
]});

Another Problem is emoji.animated is returning undefined all the time. why? https://discord.js.org/#/docs/main/stable/class/Emoji?scrollTo=animated

2
This question has an answer. Don't edit it to include a new question.André
@AndréPaulo was part of the question but ok. chill...creme

2 Answers

6
votes

Since all emoji URLs are in the form:

https://cdn.discordapp.com/emojis/${emoji.id}./* extension of the emoji e.g: .png */

Y.ou can simply just use that since you already have the ID of the emoji. Keep in mind this will only work for emojis that the bot has access to. If you would like to get the URL of emojis that the client doesn't have access to, you would need to use some regex to get the emoji ID from a message.

0
votes

Bots only have access to emojis on the servers they are in.
So if you try to grab an emoji from a server that the bot is not in, you will get undefined.

emoji.animated returns true or false (depending if its animated or not) for me. Make sure emoji is valid before checking .animated.


Just tested and you can get the URL of an emote from another server.
From message.reactions you can get all the reacted emojis. And get their URL