如何等待discord.js格式的回复?
因此,我希望我的bot执行的是等待来自用户的消息,以便当用户发送";!spec";时,bot收到该消息并将以";see或change?";响应,然后等待您键入back";see";或";change";,但我无法将其发送到WOR。我不清楚这些文档,也不确定如何操作。
这必须能够在PM中工作,因为我不想将与我计划做的事情不一致的内容作为垃圾邮件。
我已经尝试过了:
if (command === 'spec'){
message.author.send("See or Change?");
const collector = new Discord.MessageCollector(message.channel, m => m.author.id === message.author.id, { time: 10000 });
console.log(collector)
collector.on('collect', message => {
if (message.content === "See") {
message.channel.send("You Want To See Someones Spec OK!");
} else if (message.content === "Change") {
message.channel.send("You Want To Change Your Spec OK!");
}
})
我可能写错了。我不习惯图书馆。
解决方案
let filter = m => m.author.id === message.author.id
message.channel.send(`Are you sure to delete all data? `YES` / `NO``).then(() => {
message.channel.awaitMessages(filter, {
max: 1,
time: 30000,
errors: ['time']
})
.then(message => {
message = message.first()
if (message.content.toUpperCase() == 'YES' || message.content.toUpperCase() == 'Y') {
message.channel.send(`Deleted`)
} else if (message.content.toUpperCase() == 'NO' || message.content.toUpperCase() == 'N') {
message.channel.send(`Terminated`)
} else {
message.channel.send(`Terminated: Invalid Response`)
}
})
.catch(collected => {
message.channel.send('Timeout');
});
})
相关文章