This is an restricted nuke command that deletes a channel it is run in, then recreates a channel with the same name. It's useful for completely clearing the message history of a channel in case of extreme spam, and is only usable by members of your server with administrator privileges.
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
if (context.params.event.content.startsWith(`${process.env.prefix}nuke`)) {
let canUseAdminCommand = false;
let guildInfo = await lib.discord.guilds['@0.1.0'].retrieve({
guild_id: `${context.params.event.guild_id}`,
});
let roles = await lib.discord.guilds['@0.1.0'].roles.list({
guild_id: `${context.params.event.guild_id}`,
});
let userRoles = roles.filter((role) =>
context.params.event.member.roles.includes(role.id)
);
for (let i = 0; i < userRoles.length; i++) {
let _role = userRoles[i];
if (_role.permission_names.includes('MANAGE_CHANNELS')) {
canUseAdminCommand = true;
break;
}
}
if (guildInfo.owner_id === context.params.event.author.id) {
canUseAdminCommand = true;
}
if (canUseAdminCommand) {
// Can Be Removed
await lib.discord.channels['@0.2.0'].retrieve({
channel_id: `${context.params.event.channel_id}`,
});
// Deletes The Channel
const deletedChannel = await lib.discord.channels['@0.2.0'].destroy({
channel_id: `${context.params.event.channel_id}`,
});
// Logs The Nuked Channel
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${process.env.LOGCHANNEL}`,
content: ``, // you can add content
embed: {
title: `Nuke`, // you can change the title
description: `<@${context.params.event.author.id}> nuked a channel. ${deletedChannel.name}`, // you can change the message
},
});
// Creates The Same Channel Name
const newChannel = await lib.discord.guilds['@0.1.0'].channels.create({
guild_id: `${context.params.event.guild_id}`,
name: `${deletedChannel.name}`,
});
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${newChannel.id}`,
content: `Channel nuked!\n https://media1.tenor.com/images/e275783c9a40b4551481a75a542cdc79/tenor.gif?itemid=3429833`, // you can change the gif
});
} else {
if (!canUseAdminCommand) {
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Hi you dont have permission to use this command!`, // No Permission
});
}
}
}