By mentioning a user and then a role, this prefix command removes a role from a user. For example: !removerole @username @muted
// authenticates you with the API standard library
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
if (context.params.event.content.startsWith('!removerole')) {
let userString = context.params.event.content.split(' ')[1];
let roleString = context.params.event.content.split(' ')[2];
if (!userString || !roleString) {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `You must call this command like this: **!removerole @username @rolename**`
});
return;
}
try {
await lib.discord.guilds['@0.1.0'].members.roles.destroy({
role_id: roleString,
user_id: userString,
guild_id: context.params.event.guild_id
});
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Removed ${roleString} from ${userString}`
});
} catch (e) {
console.log(e);
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: [
`There was a problem removing the role.`,
`Make sure your bot's role is above the role you're trying to remove.`
].join('\n')
});
}
}