This slash command makes it easy to assign server roles to users. When registering the command, name it "delrole" and make sure you add two options: one for the user, and one for the role. You can use it like this: "/delrole <username> <role>"
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN}); {
const now = new Date()
const m = now.getMonth() + 1
const d = now.getDate()
const h = now.getHours()
const min = now.getMinutes()
const dateText = `${m}/${d}, ${h}:${min}`
if (context.params.event.member.permission_names.includes('ADMINISTRATOR')) {
let userId = context.params.event.data.options[0].value;
let roleId = context.params.event.data.options[1].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 Deleted!',
description: `${process.env.SERVERNAME} Your role on the server has been deleted!`,
color: 0xD35269,
fields: [
{
name: 'Sorun mu var?',
value: `If you think this is wrong ${process.env.SERVERNAME} Contact the authorities!`,
},
],
},
});
await lib.discord.channels['@0.1.1'].messages.create({
"channel_id": `${process.env.LOGCHANNEL}`,
"content": "**Moderation Logs |** Role Deletion",
"tts": false,
"embed": {
"type": "rich",
"title": "Role Deleted!",
"description": `${process.env.SERVERNAME} user role deleted!`,
"color": 0xD35269,
"fields": [
{
"name": "User | π€",
"value": `<@!${userId}>`
},
{
"name": "Deleted Role | β",
"value": `<@&${roleId}>`
},
{
"name": "Moderator | π¨",
"value": `<@!${context.params.event.member.user.id}>`
},
{
"name": "Time | β±οΈ",
"value": `${dateText} UTC`
},
]
}
});
let newrole = await lib.discord.guilds['@0.1.0'].members.roles.destroy({
role_id: `${roleId}`,
user_id: `${userId}`,
guild_id: `${context.params.event.guild_id}`
});
await lib.discord.channels['@0.1.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
"content": "**User Role Deleted**",
"tts": false,
"embed": {
"type": "rich",
"title": "Moderation - Role Deleted! :x:",
"description": `${process.env.SERVERNAME} user role deleted!`,
"color": 0xD35269,
"fields": [
{
"name": "User | π€",
"value": `<@!${userId}>`
},
{
"name": "Deleted Role | β",
"value": `<@&${roleId}>`
}
],
"footer": {
"text": `Role Deletion Admin: ${context.params.event.member.user.username}`
}
}
});
} else {
await lib.discord.channels['@0.1.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
"content": "**Attention**",
"tts": false,
"embed": {
"type": "rich",
"title": `You are not authorized.`,
"description": `/delrole You do not have the correct permissions for, <@!${context.params.event.member.user.id}>.\nDid you make a mistake on it? Contact an Administrator.`,
"color": 0xcf4f4f
}
});
}
}