【问题标题】:How to make the bot send personalized emojis?如何让机器人发送个性化的表情符号?
【发布时间】:2020-12-21 14:25:54
【问题描述】:

嗯,我目前正在使用表情符号 :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);
 },
};

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    官方discord.js 指南实际上有一个非常详细的解释,你可以找到here,虽然我会尝试解释它。

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

    这将产生独特的表情符号ID,格式如下:<:emoji-name:emoji-id>

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

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2019-08-01
      • 1970-01-01
      • 2020-09-22
      • 2021-04-28
      • 1970-01-01
      • 1970-01-01
      • 2019-01-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多