如何让机器人发送个性化表情符号?

SrV*_*igu 4 javascript node.js discord discord.js

好吧,我目前正在使用表情符号:x:,但在我的服务器上我有一个名为:superbotxemoji 的表情符号:我只是不知道如何让我的机器人使用它

我的代码:

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);
 },
};
Run Code Online (Sandbox Code Playgroud)

Lio*_*100 10

实际上,官方指南中有非常详细的解释,您可以在这里discord.js找到,尽管我会尝试解释它。

要发送自定义表情符号,您必须获得该表情符号的唯一性ID。要找到这一点,您必须以不和谐的方式发送前面有反斜杠的表情;本质上是逃避表情符号。

逃脱

这将导致表情符号ID在此格式中是唯一的:<:emoji-name:emoji-id>

格式

如果您将此特殊字符串粘贴到消息中,机器人将发送表情符号。但是,表情符号必须来自机器人所属的公会。

表情符号

另一方面,还有另一种非常简单的方法来使用client.emojis.cache集合和.find()方法来获取表情符号。

client.emojis.cache.find(emoji => emoji.name === '<name of emoji>')
Run Code Online (Sandbox Code Playgroud)

。寻找()

此方法还可以发送自定义表情符号,但是,这次您可以通过名称找到它们。请注意,如果给定名称有多个表情符号,则它将不起作用。

绕过这个问题的一种方法是查看集合guild.emojis.cache。这样,可能重复的表情符号的数量就会缩小。