Hides the channel where you use the prefix only admins will see the channel.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
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('ADMINISTRATOR')) {
canUseAdminCommands = true;
break;
}
}
if (guildInfo.owner_id === context.params.event.author.id) {
canUseAdminCommands = true;
}
if (canUseAdminCommands) {
if (context.params.event.content.startsWith(`${process.env.prefix}hide`)) {
await lib.discord.channels['@0.1.1'].permissions.update({
overwrite_id: `${context.params.event.guild_id}`,
channel_id: `${context.params.event.channel_id}`,
deny: `${1 << 10}`,
type: 0,
});
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embed: {
type: 'rich',
title: 'β
| This channel is now succesfully hidden!',
description: ``,
color: 0x213232,
},
});
}
if (context.params.event.content.startsWith(`${process.env.prefix}unhide`)) {
await lib.discord.channels['@0.1.1'].permissions.update({
overwrite_id: `${context.params.event.guild_id}`,
channel_id: `${context.params.event.channel_id}`,
allow: `${1 << 10}`,
type: 0,
});
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embed: {
type: 'rich',
title: 'β
| This channel is now succesfully unhidden!',
description: ``,
color: 0x213232,
},
});
}
}