【发布时间】:2020-07-16 21:27:25
【问题描述】:
我正在尝试创建一个机器人,该机器人可以向使用列出的表情符号对消息做出反应的用户添加特定角色。
使用下面的代码,我可以检查谁对消息做出了反应,我还可以检查他们对什么表情符号做出反应,但是当我尝试向他们添加角色时,会弹出错误说 user.addRole 不是一个函数 有没有办法解决这个问题?非常感谢!
创建嵌入消息供用户反应的代码
let args = message.content.substring(PREFIX.length).split(" ");
if(message.content.toLowerCase() === '?roles' && message.author.id === 'adminId' && message.channel.id === 'channel id'){
const role = new Discord.MessageEmbed()
.setTitle("ROLES")
.setColor('#6a0dad')
.setDescription('???? - ROLE1\n⚔️ - ROLE2\n???? - ROLE3')
message.channel.send(role).then(re => {re.react('????'),re.react('⚔️'),re.react('????')});
message.awaitReactions().then(collected=>{
const reaction = collected.first();
})
}
获取响应用户并尝试添加角色的代码
const bot = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
bot.on('messageReactionAdd', async (reaction, user) => {
if (reaction.partial) {
try {
await reaction.fetch();
} catch (error) {
console.log('Something went wrong when fetching the message: ', error);
return;
}
}
if(reaction.message.id === 'id of that embed message sent'){
if(reaction.emoji.name === "????"){
//console.log('ROLE1');
user.addRole('id of role 1');
}
if(reaction.emoji.name === '⚔️')
//console.log('ROLE2');
user.addRole('id of role 2');
if(reaction.emoji.name === '????')
//console.log('ROLE3');
user.addRole('id of role 3');
}
});
【问题讨论】:
标签: discord.js