node.js - Bot 未在反应角色命令中分配角色
问题描述
因此,我一直在尝试遵循有关如何设置反应角色命令的教程。即使我确实得到了我想要的反应的嵌入,但当我对它做出反应时,机器人不会分配角色。在将代码与教程进行比较后,我仍然不确定这里的问题是什么。
这是代码:
module.exports = {
name: 'reactionrole',
description: "Sets up a reaction role message!",
async execute(message, args, Discord, client){
const channel = '851809318843187262';
const yellowTeamRole = message.guild.roles.cache.find(role => role.name === "2D simp");
const blueTeamRole = message.guild.roles.cache.find(role => role.name === "3D simp");
const yellowTeamEmoji = '<:wings:851814106146144326>';
const blueTeamEmoji = '<:crowshine:851814012290203680>';
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!\n\n'
+ `${yellowTeamEmoji} for yellow team\n`
+ `${blueTeamEmoji} for blue team`);
let messageEmbed = await message.channel.send(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) {
if (reaction.emoji.name === yellowTeamEmoji) {
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;
}
});
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 === yellowTeamEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(yellowTeamRole);
}
if (reaction.emoji.name === blueTeamEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(blueTeamRole);
}
} else {
return;
}
});
}
}
解决方案
推荐阅读
- python - 在基于 django 类的视图中保存新模型后,自动将 docx/pdf 文件转换为文本文件
- pyspark - Pyspark:每个唯一ID的用户定义弹性
- php - 从 .js 文件将数组发布到 PHP 页面
- amazon-web-services - 我可以在一个 AWS 数据库集群中创建多个数据库实例吗?
- javascript - 如何包装来自第三方 api 的错误?
- mysql - 查询MySQL中至少一个孩子满足约束1且所有孩子满足约束2的所有行
- python - Python:使用 groupby 获取组中值最接近 5 的行
- spring-security-oauth2 - OAuth 错误:无效的客户端和错误的错误客户端凭据
- python - 如何用 Python(Sympy) 实现一个函数,实现与 Wolfram Mathematica 中的 ToExpression 相同?
- php - Laravel/Lighthouse - 解析为外部 API