You can use this command to announce things in an embed for other channels. This is restricted to only people with the Administrator permission due to the fact this can possibly be abused to send announcements in channels that the public can not access. To use this command it is simply: (Prefix)announce (channel ping) (Message content)
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
if (context.params.event.content.startsWith(`${process.env.PREFIX}announce`)) {
let canUseAdminCommands = 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) {
let message = context.params.event.content.split(' ').slice(2).join(' ');
let channel = context.params.event.content.split(' ')[1];
console.log(channel);
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${channel}`,
content: ' ', // required
tts: false,
embeds: [
{
type: 'rich',
title: ` `,
description: `${message}`,
color: 0xaaa5e9,
},
],
});
} else if (!canUseAdminCommands) {
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: context.params.event.channel_id,
content:
'β | Hey you need to be a server admin to use this command. Sorry!',
});
}
}