【发布时间】:2021-08-24 17:20:48
【问题描述】:
每当我运行我的代码时,我都会收到此错误
(node:552) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Emoji.
我正在尝试添加自己的表情符号,但这不起作用,我是 discord.js 的初学者 这是我第一次实际使用reactionroles,所以我不知道如何使用它们。使用正常的表情符号工作,但我想使用我的自定义表情符号
这是我的代码:
const Discord = require("discord.js");
const { MessageEmbed } = require("discord.js");
const { Color } = require("../../config.js");
module.exports = {
name: 'reactionrole',
aliases: [],
permissions: [],
description: "Sets up a reaction role message!",
run: async (client, message, args) => {
let FortniteEmoji = client.emojis.cache.get("879625063643635713");
let ApexEmoji = client.emojis.cache.get("879624843920809985");
const channel = '869871201621790741';
const RavineaRole = message.guild.roles.cache.find(role => role.name === "Fortnite Tryouts");
const YouAgainRole = message.guild.roles.cache.find(role => role.name === "Apex Legends Tryouts");
const RavineaEmoji = `FortniteEmoji`;
const YouAgainEmoji = `ApexEmoji`;
let embed = new Discord.MessageEmbed()
.setColor('#e42643')
.setTitle('Tryout For The Following Games!')
.setDescription('Enter The Tryouts!\n\n'
+ `${RavineaEmoji} for Fortnite\n`
+ `${YouAgainEmoji} for Apex Legends`);
let messageEmbed = await message.channel.send(embed);
messageEmbed.react(RavineaEmoji);
messageEmbed.react(YouAgainEmoji);
client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id == channel) {
if (reaction.emoji.name === RavineaEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(RavineaRole);
}
if (reaction.emoji.name === YouAgainEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(YouAgainRole);
}
} else {
return;
}
});
client.on('messageReactionRemove', async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id == channel) {
if (reaction.emoji.name === RavineaEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(RavineaRole);
}
if (reaction.emoji.name === YouAgainEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(YouAgainRole);
}
} else {
return;
}
});
}
}
【问题讨论】:
-
你不应该将事件放在这样的命令文件中,为它们创建一个单独的文件
标签: javascript discord discord.js