简体   繁体   中英

Get the Emoji url from a message in discord.js

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

Since all emoji URLs are in the form:

https://cdn.discordapp.com/emojis/${emoji.id}./* extension of the emoji eg: .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.

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

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