简体   繁体   English

消息收集器 discord.js

[英]Message Collector discord.js

How to make a collector stop collecting same message from a user, so the example is, if someone type catch the bot will collect it, but if he say catch again the bot will no longer collect it如何使收集器停止从用户那里收集相同的消息,例如,如果有人键入catch机器人将收集它,但如果他再次说catch机器人将不再收集它

Here's my code这是我的代码

if (command === 'coinrain') {
    message.channel.send('Coin rain has started please type `CATCH`')
    let filter = m => m.content.toLowerCase() === 'catch';
    const collector = message.channel.createMessageCollector(filter, {max: 10, time: 10000});

    collector.on('collect', m => {
        console.log(m.content);
    })

    collector.on('end', m => {
        message.channel.send({
            embed: {
                color: '#33FFF0',
                title: 'Event is over!',
                description: `${m.map(member => `${member.author.username}`).join(', ')}`
            }
        })
    })
}

As stated in the discord.js documentation, a MessageCollector has a Collected property described as: The items collected by this collectordiscord.js文档中所述, MessageCollector有一个Collected属性,描述为:此收集器收集的项目

You can use collector.collected.includes({Object-to-check}) .您可以使用collector.collected.includes({Object-to-check}) In your case you should check is a user as already sent the catch message.在您的情况下,您应该检查是否已经发送了catch消息的用户。 You can implement this check thanks to the properties author and content of Message由于Message的属性作者内容,您可以实施此检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM