javascript - 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;
解决方案
我建议使用async/await
推荐阅读
- powershell - Powershell 遍历哈希表的多维数组以查找匹配项并组合两个数组中的值
- sql - 为什么我的 SQL 子查询会出现语法错误?使用计数()
- reactjs - 反应上下文菜单
- django - 在 Django 中动态构建 Q 过滤器,使用 AND 和 OR 运算符?
- python - 无法让 Django-Simple-Captcha 工作,即使使用错误的验证码也会发帖
- linux - 如何使用 Linux 内核启动调试参数
- spring-boot - “一对多”属性值类型不应为 ________ 错误
- c# - 带有 EF 6 的 Azure 函数 - 数据库优先
- powerbi - 在 PowerBI 中更新书签
- android - compsoe NavHost 下可组合不能超过 13