我在让反应角色使用自定义表情符号时遇到问题。如果我使用不和谐表情符号,它会嵌入消息、创建反应并在点击反应时应用角色。
但是,如果我使用自定义表情符号,它会嵌入消息并创建正确的反应,但是当单击表情符号时它不会提供角色。
在不和谐和自定义表情符号之间切换时,我使用了相同的编码,唯一的变化是表情符号 ID。
我使用的完整代码是:
const { MessageReaction } = require("discord.js");
module.exports = {
name: "reactionrole",
description: "Sets up a reaction role message!",
async execute(message, args, Discord, client) {
const channel = "764347631081881660";
const sheRole = message.guild.roles.cache.find((role) => role.name === "She/Her");
const heRole = message.guild.roles.cache.find((role) => role.name === "He/Him");
const theyRole = message.guild.roles.cache.find((role) => role.name === "They/Them");
const sheEmoji = client.emojis.cache.get("805419160497946634");
const heEmoji = client.emojis.cache.get("795488864721829928");
const theyEmoji = client.emojis.cache.get("795871326446419968");
let embed = new Discord.MessageEmbed()
.setColor("#e42643")
.setTitle("Self Assignable Roles")
.setDescription(
"To Join one of our self-assignable roles, click/tap the reaction with the appropriate emoji for that role. (Note that this is purely for fun and for helpful tags & inclusivity.) By doing this we are hoping to better assist everyone in how they can address others. This also adds helpful knowledge of when someone may be on for trades, events etc.This is also not mandatory but highly recommended. isaheart \n\n" +
`List of corresponding emojis & roles:\n\n` +
`Identify yourself:\n` +
`:judy: She/Her\n` +
`:raymond: He/Him\n` +
`:zucker: They/Them\n\n` +
`Removing your reaction will also remove the role from yourself. You can have multiple roles so go ahead and choose one from each category ^^If you have any questions please feel free to reach out to any of our Admin`
);
let messageEmbed = await message.channel.send(embed);
messageEmbed.react(sheEmoji);
messageEmbed.react(heEmoji);
messageEmbed.react(theyEmoji);
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 === sheEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(sheRole);
}
if (reaction.emoji.name === heEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(heRole);
}
if (reaction.emoji.name === theyEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(theyRole);
}
} 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 === sheEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(sheRole);
}
if (reaction.emoji.name === heEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(heRole);
}
if (reaction.emoji.name === theyEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(theyRole);
}
} else {
return;
}
});
},
};
对此的任何帮助将不胜感激。
答案 0 :(得分:0)
您将 Emoji#name
用于自定义表情符号和默认表情符号。问题在于自定义表情符号没有 Emoji#name
属性(默认表情符号也是如此,它们没有 Emoji#id
)。
要解决此问题,您需要将 Emoji#id
专门用于自定义表情符号或使用 Emoji#identifier
。
这意味着你可以这样做
reaction.emoji.id === heEmoji.id
reaction.emoji === heEmoji
(不是 100% 安全)reaction.emoji.identifier=== heEmoji.identifier
。答案 1 :(得分:0)
如果您想为您的机器人使用自定义表情符号,请确保机器人在具有您想要的自定义表情符号的服务器中,我建议为此专门制作一个新服务器。接下来,您需要做的就是在表情符号之前放置一个 \
。然后它应该发送如下内容:<:emoji_name:0123456>
。您只需将其添加到所需变量的定义中即可。