問題描述
嗯,我目前正在使用表情符號 :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.
這篇關于如何讓機器人發送個性化的表情符號?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!