Reactionrole不适用于自定义表情符号,但可以使用默认表情符号



大家好,我已经试着让我的反应角色工作了一段时间,但遇到了一个问题。到目前为止,我的机器人似乎无法在我自己的discord服务器上使用自定义表情符号,但似乎与默认表情符号一起运行良好。我使用了默认和自定义表情符号进行检查。我没有2的日志,所以那里好像出了问题。我还尝试将reaction.emoji.name更改为id,但没有结果。如有任何帮助,我们将不胜感激。

const yellowTeamRole = message.guild.roles.cache.find(role => role.name === "Iron");
const blueTeamRole = message.guild.roles.cache.find(role => role.name === "Gold");
const yellowTeamEmoji = '<:Iron:1006186923917852712>';
const blueTeamEmoji = '🔴';
let embed = new Discord.MessageEmbed()
.setColor('#e42643')
.setTitle('Choose a team to play on!')
.setDescription('Choosing a team will allow you to interact with your teammates!nn'
+ `${yellowTeamEmoji} for yellow teamn`
+ `${blueTeamEmoji} for blue team`);
let messageEmbed = await message.channel.send({embeds: [embed]});
messageEmbed.react(yellowTeamEmoji);
messageEmbed.react(blueTeamEmoji);
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) {
console.log('1');
if (reaction.emoji.name === yellowTeamEmoji) {
console.log('2');
await reaction.message.guild.members.cache.get(user.id).roles.add(yellowTeamRole);
}
if (reaction.emoji.name === blueTeamEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(blueTeamRole);
}
} else {
return;
}
});

您不会得到日志,因为在if语句中,您只将整个emote与其名称进行比较。

你基本上是这样做的:if("Iron" === "<:Iron:1006186923917852712>")

你应该做的是在你的客户或公会中获得表情,并通过.name访问名称属性

// the id of your emote
const foundEmote = client.emojis.cache.find(e => e.id === "1006186923917852712");
if(reaction.emoji.name === foundEmote.name) {
// your code
}

相关内容

最新更新