This snippet aallows a user to create a role with a given name via a slash command /createrole. Feel free to change the color, currently it is of an obsidian like color. The created role is mentionable but you can also change that. Register the slash command with an Option type String at https://autocode.com/tools/discord/command-builder/. IF YOU NEED HELP SETTING UP, you can ping @Zeno in the Autocode Discord for support. Hope you enjoy!
// Using Node.js 14.x +
// use "lib" package from npm
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let isMANAGE_ROLES =
(context.params.event.member.permissions & (1 << 28)) === 1 << 28;
if (isMANAGE_ROLES) {
// make API request
let name = context.params.event.data.options[0].value;
let result = await lib.discord.guilds['@0.1.0'].roles.create({
name: `${name} `,
guild_id: `${context.params.event.guild_id}`, // required
color: 131644,
hoist: false,
mentionable: true,
});
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `**<@${context.params.event.member.user.id}> - role successfully created!**`,
});
} else {
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `**<@${context.params.event.member.user.id}> - You need the MANAGE_ROLES permission to use this command**`,
});
}