【发布时间】:2020-08-18 19:06:25
【问题描述】:
我正在为我的学校编写一个机器人,我目前正在开发一项功能,如果学生发送特定消息并且如果老师使用特定表情符号对其做出反应,则该功能使学生能够在语音频道中交谈。这是代码。
client.on('message', handMsg => {
if (!handRaiseModeActive) return;
if ((handMsg.content.includes(PREFIX + 'talk')) && handMsg.channel.id === hgCID) {
superConsole(`**@${handMsg.author.tag} asked to speak ||\`${handMsg.author.id}\`||**`)
handMsg.react('✅')
handMsg.react('❎')
client.on('messageReactionAdd', (reaction, user) => {
if (reaction._emoji.name == '✅' && user.id !== botID && (user.id == teacherID || devID.includes(user.id))) {
handMsg.member.voice.setMute(false)
handMsg.reactions.removeAll();
superConsole(`handRaiseMode | permission to speak given to @${handMsg.author.tag} ||\`${handMsg.author.id}\`||`)
} else if (reaction._emoji.name == '❎' && user.id !== botID && (user.id == teacherID || devID.includes(user.id))) {
handMsg.reactions.removeAll()
superConsole(`handRaiseMode | permission to speak denied to @${handMsg.author.tag} ||\`${handMsg.author.id}\`||`)
}
});
}
})
teacherID 是老师的 ID,devID 是一个包含所有开发者 ID 的数组,botID... 机器人 ID。一条命令将handRaiseModeActive 设置为真或假。 superConsole 是一个函数,其中事件在通道和控制台中发送。
这是我的问题: 学生第一次请求发言权限时,一切正常,但如果之后,另一个学生通过 handRaiseMode 获得发言权限,则之前请求发言的所有学生都将被取消静音......看起来像 @987654327 @ 仍在工作,尽管它应该已经结束。我真的不明白它是如何工作的。需要帮助!
提前感谢您的回答。
【问题讨论】:
-
如果我的回答解决了您的问题,请接受它,让其他人知道什么有效
标签: javascript node.js discord.js