How to make the bot send personalized emojis?

倾然丶 夕夏残阳落幕 提交于 2021-02-10 17:26:14

问题


Well, I'm currently using the emoji :x:, but on my server I have an emoji called :superbotxemoji: I just don't know how I get my bot to use it

My code:

const Discord = require('discord.js');

module.exports = {
 name: 'say',
 description: 'say',
 execute(message, args) {
  const { prefix, token } = require('../config.json');

  if (!message.member.hasPermission('ADMINISTRATOR'))
   return message.channel.send({
    embed: {
     color: 16777201,
     description: `:x: | ${message.author}, You are not allowed to use this command.`,
     footer: {
      text: `   | Required permission: ADMINISTRATOR`,
     },
    },
   });

  if (!args.length)
   return message.channel.send({
    embed: {
     color: 16777201,
     description: `:x: | ${message.author}, You need to put a message.`,
     footer: {
      text: `   | Example: !say hello`,
     },
    },
   });

  const sayMessage = args.join(' ');
  message.delete({ timeout: 1 });
  message.channel.send(sayMessage);
 },
};

回答1:


There is actually a very detailed explanation from the official discord.js guide which you can find here, although I'll try to paraphrase it.

To send a custom emoji, you must get that emoji's unique ID. To find that, you must send the emote in discord with a backslash in front of it; essentially escaping the emoji.

Escape

This will result in the emojis unique ID in this format: <:emoji-name:emoji-id>

Format

If you paste this special string into a message, the bot will send the emoji. However, the emoji must be from a guild the bot is part of.

Emoji

On the other hand, there's another very easy way to get an emoji using the client.emojis.cache collection and the .find() method.

client.emojis.cache.find(emoji => emoji.name === '<name of emoji>')

.find()

This method will also make it possible to send custom emojis, however, this time you can find them by name. Be careful, if there are more than one emojis by the given name, it will not work.

A way to bypass this problem would be looking at a guild.emojis.cache collection. This way the amount of possible duplicate emojis would be narrowed down.




回答2:


You need to get the bot to join the server with :superbotxemoji:, then it can use the emoji in any server



来源:https://stackoverflow.com/questions/63705166/how-to-make-the-bot-send-personalized-emojis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!