使用 discord.js 检查是否有人在 5 秒内发送了 2 条相同的消息
Check if someone send 2 same messages in 5 seconds with discord.js
有谁知道如何检查是否有人在同一个频道中两次发送相同的消息,间隔为 5 秒(两次消息之间可能有其他人的其他消息)?
(我是 Javascript 和 Discord.js 的新手)
如果有人能帮助我,那就太好了。
您可以使用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);
});
有谁知道如何检查是否有人在同一个频道中两次发送相同的消息,间隔为 5 秒(两次消息之间可能有其他人的其他消息)?
(我是 Javascript 和 Discord.js 的新手)
如果有人能帮助我,那就太好了。
您可以使用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);
});