Adds a prefix command `!delete-this-channel` which will delete the current channel if the user has one of the admin roles.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const event = context.params.event;
let adminRoles = ['YOUR_ADMIN_ROLE_ID_HERE', 'ANOTHER_ADMIN_ROLE_ID_HERE'];
if (event.content.startsWith('!delete-this-channel')) {
let adminRole = event.member.roles.find((roleId) => {
return adminRoles.find((adminRoleId) => adminRoleId === roleId);
});
if (!!adminRole) {
await lib.discord.channels['@0.2.0'].destroy({
channel_id: event.channel_id,
});
} else {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Sorry, you don't have the right role to use this command.`,
});
}
}