Prefix command that only allows users with certain roles to run it. Paste your command name and admin role id where prompted.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let adminRoles = [
'YOUR_ADMIN_ROLE_ID_HERE',
'ANOTHER_ADMIN_ROLE_ID_HERE'
];
if (context.params.event.content.startsWith('!restrictedcommand')) {
let adminRole = context.params.event.member.roles.find((roleId) => {
return adminRoles.find((adminRoleId) => {
return adminRoleId === roleId;
});
});
if (!!adminRole) {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Congratulations! Since you have the <@&${adminRole}> role, you can use this command!`
});
} else {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Sorry, you don't have permission to use this command. You need to have the <@&${adminRole}> role.`
});
}
}