Search code examples
discorddiscord.jsbots

Check if command is in certain channel


I have a script that checks if a user has a certain role to see if they can use a certain command. Those role ids are stored in a json file like so:

[ "roleid1", "roleid2", "roleid3" ]

i would like to use the same concept to store the channel ids, but cannot figure out how. this is the code for my role checking:

delete require.cache[require.resolve("./resources/lookup_perms.json")];
const roles = require("./resources/lookup_perms.json");
const result = msg.member.roles.cache.some(r => roles.includes(r.id));
    
Actions.storeValue(result, 1, "auth", cache);
Actions.callNextAction(cache)

Solution

  • Check the message channel id

    if (msg.channel.id === "CHANNEL_ID_HERE") {
        // Code here
    }
    

    Replace CHANNEL_ID_HERE with the channel id you want

    Edit: If you want to check an array of channels you can use .includes like this:

    if (["ChannelId1", "ChannelId2"].includes(msg.channel.id))
    {
        // Code here
    }