首页 > 解决方案 > Discord.js 让你的机器人等待回复

问题描述

我正在制作一个机器人,当您执行 !train 时,它会在公告中说一些内容,还会向作者发送消息,并告诉他在完成训练后输入完成,然后在它说训练正在进行的地方编辑消息或向其发送新消息公告。

case 'train':
  if (message.member.roles.has('649756129240547348')) {
    const user60 = message.author.username;
    bot.channels.get("649756880314302464").send('<@&673125623463673857>');
    bot.channels.get("649756880314302464").send('Subway Security Trainings!! \n Are you still awaiting tryout? Then come along to this training.\n (Slock in 10-15 minutes)\n https://www.roblox.com/games/4582202027/Subway-Security-Tryout-Centre\n https://discord.gg/bvYgmDe');
    bot.channels.get("649756880314302464").send('Training underway, hosted by ' + user60);
    message.author.send('Tell me when you have finished(say Finished)');
    const collector = new Discord.MessageCollector(message.channel, m => m.author.id === message.author.id, {
      time: 100000
    });
    collector.on('collect', message => {
      if (message.content == 'Finished') {
        bot.channels.get("649756880314302464").send('Training has finished. Hosted by ' + user60);
        message.channel.sendMessage('Thanks!')
      } else if (message.content == 'finished') {
        bot.channels.get("649756880314302464").send('Training has finished. Hosted by ' + user60);
        message.channel.sendMessage('Thanks!')
      }
    })
  } else {
    message.channel.sendMessage('You do not have the permission to do this command')
  }
  break;

标签: javascriptvisual-studiodiscorddiscord.js

解决方案


我建议使用async/await


推荐阅读