How to make the bot send personalized emojis?(如何让机器人发送个性化的表情符号?)
问题描述
嗯,我目前正在使用表情符号 :x:,但在我的服务器上我有一个名为 :superbotxemoji 的表情符号:我只是不知道我是怎么做到的让我的机器人使用它
我的代码:
const Discord = require('discord.js');模块.exports = {名称:'说',描述:'说',执行(消息,参数){const { 前缀,令牌 } = require('../config.json');if (!message.member.hasPermission('ADMINISTRATOR'))返回 message.channel.send({嵌入:{颜色:16777201,描述:`:x:|${message.author}, 你不能使用这个命令.`,页脚:{文本:` |所需权限:管理员`,},},});如果(!args.length)返回 message.channel.send({嵌入:{颜色:16777201,描述:`:x:|${message.author}, 你需要发消息.`,页脚:{文本:` |示例:!打个招呼`,},},});const sayMessage = args.join(' ');message.delete({ timeout: 1 });message.channel.send(sayMessage);},};其实官方discord.js指南里面有非常详细的解释,你可以找到 集合和 .find() 方法.
client.emojis.cache.find(emoji => emoji.name === '<表情符号的名称>')此方法还可以发送自定义表情符号,但是这次您可以通过名称找到它们.请注意,如果给定名称的表情符号不止一个,它将不起作用.
绕过这个问题的一种方法是查看 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.
这篇关于如何让机器人发送个性化的表情符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何让机器人发送个性化的表情符号?
基础教程推荐
- 如何在特定日期之前获取消息? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
