【发布时间】:2021-04-25 07:59:14
【问题描述】:
我想制作一个不和谐的机器人,如果我在特定时间输入完成,它会问我一个问题,如果它的答案应该说你赢了,但如果它达到 7 秒,它应该说时间到但我没有知道有时它会按时间向频道发送垃圾邮件,我该如何解决,请我被困在那里 8 小时?
/* === countries image === */
var kurdistan = "https://upload.wikimedia.org/wikipedia/commons/thumb/3/35/Flag_of_Kurdistan.svg/800px-Flag_of_Kurdistan.svg.png";
var catalonia = "https://upload.wikimedia.org/wikipedia/commons/thumb/c/ce/Flag_of_Catalonia.svg/810px-Flag_of_Catalonia.svg.png";
var palastine = "https://upload.wikimedia.org/wikipedia/commons/thumb/0/00/Flag_of_Palestine.svg/800px-Flag_of_Palestine.svg.png";
/* === countries names === */
const obj = [
kurdistan,
catalonia,
palastine
];
/* === code === */
client.on('message', async message => {
if(message.author.bot) return;
const ranImg = Math.floor(Math.random() * obj.length);
if(message.content === 'flag') {
const embed = new Discord.MessageEmbed();
embed.setTitle('Flag guesser');
embed.setDescription('which countries flag does this belong?');
embed.setImage(obj[ranImg]);
embed.setColor(0x3aeb34);
embed.setFooter('this game provided by by me');
embed.setTimestamp();
message.channel.send(embed).then(() => {
let filter = m => m.author.id === message.author.id;
message.channel.awaitMessages(filter, { max: 1, time: '7000', errors: ['time'] })
.then(collected => {
//when it gives me the image and I write the correct answer of the obj[ranImg] it doesn't says you win all the time it says try again ????????????????????????????????
if (collected.first().content === obj[ranImg]) {
return message.channel.send(':white_check_mark: You win!') //they won
} else {
return message.channel.send(`:x: Oooh close! Try again!`); // they lost
}
})
.catch(collected => {
return message.channel.send('times up! no answers were collected!');
});
});
}
}
);
【问题讨论】:
标签: javascript node.js asynchronous discord discord.js