【发布时间】:2018-04-20 13:16:44
【问题描述】:
所以我是不和谐机器人和 js 的新手,我正在玩自己的机器人。我想做一个打字小游戏。当您在聊天中键入 ?type 时,机器人会在聊天中说些什么,然后在倒计时时编辑该消息。倒计时结束后,会显示随机生成的单词。玩家需要在聊天中输入准确的随机词,机器人会显示所花费的总时间。
这是我的代码:
case "type":
let randomWord = Math.random().toString(36).replace(/[^a-z]+/g, '');
let timer = 3;
message.channel.send("Generating a new word..")
.then((msg)=> {
var interval = setInterval(function () {
msg.edit(`Starting in **${timer--}**..`)
}, 1000)
});
setTimeout(function() {
clearInterval(interval);
message.channel.send(randomWord)
.then(() => {
message.channel.awaitMessages(response => response.content == randomWord, {
max: 1,
time: 10000,
errors: ['time'],
})
.then(() => {
message.channel.send(`Your time was ${(msg.createdTimestamp - message.createdTimestamp) / 1000} seconds.`);
})
.catch(() => {
message.channel.send('There was no collected message that passed the filter within the time limit!');
});
});
}, 5000);
break;
当前代码在倒数 0 后停止。
我不明白为什么message.channel.send(randomWord) 不起作用。如果有人可以帮助我更改此代码以使用异步并等待是否可行,我也会很高兴。
【问题讨论】:
标签: javascript discord discord.js