Проверьте, отправляет ли кто-то 2 одинаковых сообщения за 5 секунд с помощью discord.js - PullRequest
0 голосов
/ 09 сентября 2018

Кто-нибудь знает, как проверить, отправляет ли кто-то одно и то же сообщение два раза в одном и том же канале с интервалом в 5 секунд (между этими двумя сообщениями могут быть другие сообщения от других людей)?

(я новичок в Javascript и Discord.js)

Если бы кто-то мог мне помочь, было бы здорово.

1 Ответ

0 голосов
/ 11 сентября 2018

Вы можете использовать TextChannel.awaitMessages()

client.on('message', message => {
  // this function can check whether the content of the message you pass is the same as this message
  let filter = msg => {
    return msg.content.toLowerCase() == message.content.toLowerCase() && // check if the content is the same (sort of)
           msg.author == message.author; // check if the author is the same
  }

  message.channel.awaitMessages(filter, {
    maxMatches: 1 // you only need that to happen once
    time: 5 * 1000 // time is in milliseconds
  }).then(collected => {
    // this function will be called when a message matches you filter
  }).catch(console.error);
});
...