【发布时间】:2021-09-30 02:16:24
【问题描述】:
我有一个有效的反应角色菜单,可以很好地分配和取消角色,直到机器人重新启动然后它停止给予/取消角色,我正在努力寻找与此反应菜单工作方式相匹配的解决方案。
client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot)
if(!reaction.message.guild) return;
if (reaction.message.channel.id === channel) {
if (reaction.emoji.name === reactone){
await reaction.message.guild.members.cache.get(user.id).roles.add(roleone);
}
if (reaction.emoji.name === reacttwo){
await reaction.message.guild.members.cache.get(user.id).roles.add(roletwo);
}
if (reaction.emoji.name === reactthree){
await reaction.message.guild.members.cache.get(user.id).roles.add(rolethree);
}
if (reaction.emoji.name === reactfour){
await reaction.message.guild.members.cache.get(user.id).roles.add(rolefour);
}
//add more here
} else{
return
}
});
【问题讨论】:
-
有错误吗?尝试做一些调试;将
console.log语句放在这段代码的各个部分(例如,在事件处理程序的顶部,在每个if条件检查之后,在每个角色分配之前和之后),看看你的代码有多远。这样做会告诉您代码的哪一部分是问题所在,或者您的代码是否正在执行。 -
我觉得可能跟缓存有关
-
我看不到任何错误出现,并且在机器人重新启动之前它工作正常,我也认为它与缓存有关但是我正在努力查看我需要修复/编辑的位置以确保它缓存正确
标签: discord.js