Skip to content
Advertisement

How would I bypass a cetian role on a cooldown script discord.js/ command that restricts a certain command to a certain channel

This is the current code that I have, I would like to make it where if you have a certain role then you can bypass the cooldown, also if anyone knows how to make a command that restricts a certain command to a certain channel, instead of having this really long message.channel.id.

const Discord = require('discord.js');
const fetch = require('node-fetch');
const talkedRecently = new Set();
module.exports.run = async(client, message, args, queue, searcher,   ) => {

      if (talkedRecently.has(message.author.id)) {
            message.channel.send("Wait 1 minute before getting typing this again. " +'<@'+ message.author.id + '>');
    } else {


    switch(args[0].toLowerCase()){
        case 'neko':
            if(message.channel.id === '739002385531404288'||
            message.channel.id === '646849145289834506'||
            message.channel.id === '785079847763574794'||
            message.channel.id === '782891383361896469'||
            message.channel.id === '784417039425994772'){  
        fetch('https://nekos.life/api/v2/img/lewd')
        .then(res => res.json())
        .then(json => {
            let nekoEmbed = new Discord.MessageEmbed()
            .setTitle('Lewd Nekos! (=^・ω・^=)')
            .setImage(json.url)
            message.channel.send(nekoEmbed)
            
            })
        }else{
            return}}
            
     talkedRecently.add(message.author.id);
        setTimeout(() => {
        
        talkedRecently.delete(message.author.id);
        }, 60000);
    }        
            
            
            
            
            }

    module.exports.config = {
        name: "hentai",
        aliases: ['ht']  
    }
    ```

Advertisement

Answer

Answering Your First Question: Simply check if the member has a certain role. If they do, construct your if statement so that it will not fire if they have that role Make sure to use message.member when checking roles

if (talkedRecently.has(message.author.id) && !message.member.roles.cache.has('bypass role id here')) {
   // Your cooldown message
}

Learn more about Roles#has

Answering your 2nd question: You can have an array of channel id’s then use includes to check if any of the id’s in the array match the current channel id

const ids = ['id1', 'id2', 'id3', 'id4'] // And so on

if (ids.includes(message.channel.id)) {
   // Your Code
}

Learn more about Array.prototype.includes

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement