如何使机器人发送个性化的表情符号? [英] How to make the bot send personalized emojis?

查看:73
本文介绍了如何使机器人发送个性化的表情符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我的代码:

  const Discord = require('discord.js');module.exports = {名称:"say",描述:说",执行(消息,args){const {prefix,token} = require('../config.json');如果(!message.member.hasPermission('ADMINISTRATOR'))返回message.channel.send({嵌入:{颜色:16777201,说明:`:x:|$ {message.author},不允许使用此命令.页脚:{文字:`|所需权限:ADMINISTRATOR`,},},});如果(!args.length)返回message.channel.send({嵌入:{颜色:16777201,说明:`:x:|$ {message.author},您需要输入一条消息.页脚:{文字:`|例如:!say hello`,},},});const sayMessage = args.join('');message.delete({timeout:1});message.channel.send(sayMessage);},}; 

解决方案

实际上,官方 discord.js 指南中有非常详细的解释,您可以找到集合和 client.emojis.cache.find(emoji => emoji.name ==='< emoji名称>')

此方法还可以发送自定义表情符号,但是,这次您可以按名称查找它们.请注意,如果给定名称的表情符号不止一个,它将无法正常工作.

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

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);
 },
};

解决方案

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.

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

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.

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>')

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.

这篇关于如何使机器人发送个性化的表情符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆