我的 messageReactionAdd 出现了以下问题:
bot.on("ready", () =>
{
// I cache the selected message declared before in message_id and channel_id
bot.channels.cache.get(channel_id).messages.fetch(message_id).then(m => {
console.log("Cached reaction message.");
}).catch(e => {
console.error("Error loading message.");
console.error(e);
});
})
bot.on("messageReactionAdd", (reaction, user) => {
if(reaction.emoji.name == "?" && reaction.message.id === message_id)
try {
const role = reaction.message.channel.guild.roles.cache.find(role => role.name == "Membres");
reaction.message.guild.member(user).roles.add(role);
} catch {
console.log('Error : can\'t add the role');
}
});
问题在于代码仅与缓存邮件的所有者一起工作,而与频道中的其他用户一起工作。
你知道为什么吗?
答案 0 :(得分:0)
如果要创建反应角色系统,可以使用raw
bot.on('raw', event => {
if (event.t === 'MESSAGE_REACTION_ADD' || event.t == "MESSAGE_REACTION_REMOVE"){
let reaction = event.d.emoji
let userID = enevt.d.user_id
let messageID = event.d.message_id
let guildID = event.d.guild_id
let guild = bot.guilds.cache.get(guildID)
let role = guild.roles.cache.get(role_id) //role id is defined by yourself
let user = guild.members.cache.get(userID) //You need to enable server members intent to use that command
}
}
,我创建了所有可以开发反应角色系统的id和对象。 如果未启用服务器成员意图,则可以使用:
guild.members.fetch(userID).then(user => user.roles.add(role))