【问题标题】:Check if someone send 2 same messages in 5 seconds with discord.js使用 discord.js 检查是否有人在 5 秒内发送了 2 条相同的消息
【发布时间】:2019-02-14 00:15:30
【问题描述】:

有谁知道如何检查某人是否在同一频道中以 5 秒的间隔发送了两次相同的消息(两条消息之间可能还有其他人的其他消息)?

(我是 Javascript 和 Discord.js 的新手)

如果有人可以帮助我,那就太好了。

【问题讨论】:

  • 欢迎来到 Stack Overflow!请带上tour 并通读help center,特别是如何提问。你最好的选择是做你的研究,搜索关于 SO 的相关主题,然后试一试。在进行更多研究和搜索后,发布您的尝试Minimal, Complete, and Verifiable example,并具体说明您遇到的问题,这可以帮助您获得更好的答案。
  • 你这是什么意思?您是否要检查用户是否两次发送相同的消息?一条消息和另一条消息之间可以经过多长时间?他们必须在同一个频道吗?他们必须一个接一个地直接进行还是仅仅在同一时间跨度内进行?如果您可以添加更多细节并告诉我们您的想法以及您已经尝试过的内容,我将很乐意为您提供帮助:)
  • @FedericoGrandi 我已经更新了帖子:) 我希望我解释得更好

标签: javascript discord discord.js


【解决方案1】:

您可以使用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);
});

【讨论】:

  • 你在 maxMatches: 1 之后错过了逗号
猜你喜欢
  • 1970-01-01
  • 2021-03-03
  • 2020-02-26
  • 2023-03-11
  • 1970-01-01
  • 2021-10-14
  • 2018-07-21
  • 2017-09-17
  • 2021-04-18
相关资源
最近更新 更多