最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

if条件不会停止启用

网站源码admin16浏览0评论

if条件不会停止启用

if条件不会停止启用

我正在为我的学校编写机器人程序,目前正在开发一项功能,如果学生发送了特定的消息,并且老师对特定的表情符号做出了反应,则该功能使学生可以在语音通道中进行交谈。这是代码。

if (handRaiseModeActive === true) {
client.on('message', handMsg => {
  if (handRaiseModeActive === true) {
  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设置为true或false。 superConsole是一项功能,通过该功能可以在通道和控制台中发送事件。

这是我的问题:第一次有学生要求发言权时,一切正常,但是,如果此后,另一名学生获得了使用handRaiseMode发言的权限,则以前要求发言的所有学生都不会被忽略... [C0 ]尽管实际上应该已经结束了,但它仍在工作。我不太了解它是如何工作的。需要帮助!

感谢您的回答。

注意:我知道有两个l.4,谢谢。第二个是没用的。我将其删除。

回答如下:

我认为您的问题可能是因为您嵌套了事件,这是一个坏习惯,无论它会导致内存泄漏或其他问题。

我认为您的问题可以简单地使用if (handRaisModeActive === true)来解决:

awaitReactions()

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论