0

I would like to block a user who want to send another message in a specific channel :

client.on("message", async message => {
    if ((message.content === config.RUN) && message.member.roles.cache.has(config.ROLE_ID)) {
        if (message.channel.type === 'DM') return;
                let filter = m => !m.author.bot;
                let destination = client.channels.cache.get(config.CHANNEL_ID);
                message.author.createDM().then(dmchannel => {
                    dmchannel.send(textDM.FIRST_DM);
                    const collector = new discord.MessageCollector(dmchannel, filter);
                    collector.on('collect', (m, col) => {
                        console.log(m.content);
                        if (m.content.startsWith("ok")) { // here condition if user already sent msg

                          // Do something 

                         }

1 Answer 1

0

You can use a variable to count the quantity of the message sent by the user. If it reaches 2, you can execute your desired code.

To use this for specific user, do:

var messageAmount = {}
var amount = 0

if (message.content.startsWith("ok")) {

        const user = message.author.id

        if(messageAmount[`${user}`] === 1) { // is 1 because it checks for 2 after it has been assigned, if(messageAmount = x-1) 

            // Do something 
            message.channel.send("You cannot say that again until (...) finishes")


            // then reset it
            messageAmount[`${user}`] = 0
            amount = 0

        } else {
                
            ++amount
    
            messageAmount[`${user}`] = amount
        }
    }

To use this globally:

var messageAmount = 0


if (m.content.startsWith("ok")) {

    ++messageAmount

    if(messageAmount === 2) {
          // Do something 
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.