This snippet sends a message to the whitelisted channels, if the command was used in a different channel, it sends a different message. Kindly read the code to understand where you need to place your channel IDs. (Credits to @jacoblee's "Discord User-Restricted Prefix Command" snippet)
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let event = context.params.event;
// Stores the whitelisted channel IDs
// Replace the placeholders with real channel IDs
const W_CHANNEL_IDs = [
'000000000000000000',
'000000000000000000', // You can add more following the format
];
if (event.content === '!restricted-command') {
// Checks if the channel ID is one of the in the array above
if (W_CHANNEL_IDs.includes(event.channel_id)) {
await lib.discord.channels['@0.2.1'].messages.create({
channel_id: event.channel_id,
content: `Cool! You can use this command here.`, // You can change the response to whatever you want
});
} else {
await lib.discord.channels['@0.2.1'].messages.create({
channel_id: event.channel_id,
content: `Oops! You can't use this command here.`, // You can change the response to whatever you want
});
}
}