Fill the ADMIN_ROLE_HERE and ANOTHER_ADMIN_ROLE_HERE with the ID's of your admin role. Owner also needs to have admin role inorder to use it. Use !addrole to add and !delrole to delete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let adminRoles = [
'ADMIN_ROLE_HERE',
'ANOTHER_ADMIN_ROLE_HERE'
];
if (context.params.event.content.startsWith('!addrole')) {
let name = context.params.event.content.split(' ')[1];
let color = context.params.event.content.split(' ')[2];
let hoist = context.params.event.content.split(' ')[3];
let adminRole = context.params.event.member.roles.find((roleId) => {
return adminRoles.find((adminRoleId) => {
return adminRoleId === roleId;
});
});
if (!name) {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embed: {
type: 'rich',
title: 'Please fill all the requirements ',
description:
'**For !addrole**\nUsage: !addrole [name] [hex color] [hoist]\nExample: !addrole Test FF0000 true\n\n**For !delrole**\nUsage: !delrole [role] \nExample: !delrole @coolppl\n',
color: 0x060606,
},
});
} else if (!color) {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embed: {
type: 'rich',
title: 'Please fill all the requirements ',
description:
'**For !addrole**\nUsage: !addrole [name] [hex color] [hoist]\nExample: !addrole Test FF0000 true\n\n**For !delrole**\nUsage: !delrole [role] \nExample: !delrole @coolppl\n',
color: 0x060606,
},
});
} else if (!hoist) {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embed: {
type: 'rich',
title: 'Please fill all the requirements ',
description:
'**For !addrole**\nUsage: !addrole [name] [hex color] [hoist]\nExample: !addrole Test FF0000 true\n\n**For !delrole**\nUsage: !delrole [role] \nExample: !delrole @coolppl\n',
color: 0x060606,
},
});
}
if (!!adminRole) {
let result = await lib.discord.guilds['@0.1.0'].roles.create({
guild_id: `${context.params.event.guild_id}`,
name: `${name}`,
color: parseInt(`0x${color}`),
hoist: Boolean(hoist),
});
} else {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Sorry, you don't have permission to use this command.`
});
}
}
if (context.params.event.content.startsWith('!delrole')) {
let role = context.params.event.content.split(' ')[1];
let adminRole = context.params.event.member.roles.find((roleId) => {
return adminRoles.find((adminRoleId) => {
return adminRoleId === roleId;
});
});
if (!role) {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embed: {
type: 'rich',
title: 'Please fill all the requirements ',
description:
'**For !addrole**\nUsage: !addrole [name] [hex color] [hoist]\nExample: !addrole Test FF0000 true\n\n**For !delrole**\nUsage: !delrole [role] \nExample: !delrole @coolppl\n',
color: 0x060606,
},
});
}
if (!!adminRole) {
let result = await lib.discord.guilds['@0.1.0'].roles.destroy({
role_id: `${role}`,
guild_id: `${context.params.event.guild_id}`,
});
} else {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Sorry, you don't have permission to use this command.`
});
}
}