Use the prefix commands "!lockdown" to lock and "!unlock" to unlock the server channels whenever there is need.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
//anyone can use this command so make sure you add some extras to check that
if (context.params.event.content.startsWith('!lockdown')) {
let channels = await lib.discord.guilds['@0.1.0'].channels.list({
guild_id: `${context.params.event.guild_id}`,
});
const role = await lib.discord.guilds['@0.1.0'].roles
.list({
guild_id: `${context.params.event.guild_id}`,
})
.then((roles) => roles.find((x) => x.name === '@everyone'));
channels.forEach(async (channel) => {
await lib.discord.channels['@0.1.1'].permissions.update({
overwrite_id: role.id,
channel_id: channel.id,
deny: `${(1 << 11) + (1 << 10)}`,
type: 0,
});
});
return lib.discord.channels['@0.2.0'].messages.create({
content: `Locked all the channels 🔒`,
channel_id: context.params.event.channel_id,
});
} else if (context.params.event.content.startsWith('!unlock')) {
let channels = await lib.discord.guilds['@0.1.0'].channels.list({
guild_id: `${context.params.event.guild_id}`,
});
const role = await lib.discord.guilds['@0.1.0'].roles
.list({
guild_id: `${context.params.event.guild_id}`,
})
.then((roles) => roles.find((x) => x.name === '@everyone'));
channels.forEach(async (channel) => {
await lib.discord.channels['@0.1.1'].permissions.update({
overwrite_id: role.id,
channel_id: channel.id,
allow: `${(1 << 11) + (1 << 10)}`,
type: 0,
});
});
return lib.discord.channels['@0.2.0'].messages.create({
content: `Unlocked all the channels 🔓`,
channel_id: context.params.event.channel_id,
});
}