Removes a role from a user with a simple slash command, make sure you set the command up with the `USER PING` first and `ROLE PING` second and the `REASON` last in https://autocode.com/tools/discord/command-builder/
// authenticates you with the API standard library
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const now = new Date()
const m = now.getMonth() + 1 // 0 index based
const d = now.getDate()
const h = now.getHours()
const min = now.getMinutes()
const dateText = `${m}/${d}, ${h}:${min}` // -> "6/6, 15:19"
if (
context.params.event.member.permission_names.includes('ADMINISTRATOR')
) {
let userId = context.params.event.data.options[0].value;
let role = context.params.event.data.options[1].value;
let reason = context.params.event.data.options[2].value;
await lib.discord.users['@0.1.1'].dms.create({
recipient_id: `${userId}`,
content: `**${process.env.SERVERNAME} Alert**`,
tts: false,
embed: {
type: 'rich',
title: 'Role Removed',
description: `"Hi there im sorry to inform you but your role/rank has been removed either for violation of our rules or abuse. Please visit https://skypixelmc.xyz/support for more information.`,
color: 0xE8985E,
fields: [
{
name: 'Reason',
value: `${reason}`,
},
],
},
});
// make API request
let result = await lib.discord.guilds['@0.1.2'].members.roles.destroy({
role_id: `${role}`, // required
user_id: `${userId}`, // required
guild_id: `${context.params.event.guild_id}` // required
});
await lib.discord.channels['@0.1.1'].messages.create({
"channel_id": `${process.env.LOGCHANNEL}`,
"content": "**Moderation Logs |** Role-Removed",
"tts": false,
"embed": {
"type": "rich",
"title": "Role-Removed",
"description": `Role removed from <@!${userId}>`,
"color": 0xE8985E,
"fields": [
{
"name": "User",
"value": `<@!${userId}>`
},
{
"name": "Role/rank removed",
"value": `${role}`
},
{
"name": "Reason",
"value": `${reason}`
},
{
"name": "Moderator",
"value": `<@!${context.params.event.member.user.id}>`
},
{
"name": "Time",
"value": `${dateText} UTC`
},
]
}
});
await lib.discord.channels['@0.1.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
"content": " ",
"tts": false,
"embed": {
"type": "rich",
"title": " ",
"description": `Role successfully removed from <@!${userId}>`,
"color": 0xE8985E,
"fields": [
],
"footer": {
"text": `Removed by ${context.params.event.member.user.username}`
}
}
});
}
else {
await lib.discord.channels['@0.1.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
"content": "**Error**",
"tts": false,
"embed": {
"type": "rich",
"title": `Invalid permissions`,
"description": `You do not have the correct permissions for /remove-role, <@!${context.params.event.member.user.id}>.\nThink this is an error? Contact a Admin.`,
"color": 0xcf4f4f
}
});
}