Created
December 17, 2020 20:20
-
-
Save 3urobeat/37747ddd0652b541b6e5195ac054bfda to your computer and use it in GitHub Desktop.
A role promotion cmd I wrote for the official Discord Server of the YT channel "Marmeladenoma"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Promote command plugin by https://github.com/HerrEurobeat | |
//This code isn't really customizeable because it is only needed for a specific use case | |
//Made for the Discord Bot of the official Discord Server of the YouTube channel "Marmeladenoma": https://www.youtube.com/channel/UCSSUG_vo76v04FKRnsWavMA | |
module.exports.run = async (bot, msg, args) => { | |
const config = require("./config.json") | |
if (args.length < 2) return bot.createMessage(msg.channel.id, "Fehler: Dir scheint ein Argument zu fehlen. Bitte achte auf die korrekte Eingabe.\nSyntax: !promote @Nutzer Rollenname"); | |
if (msg.mentions.length < 1) return bot.createMessage(msg.channel.id, `Fehler: Der Nutzer "${args[0]}" konnte leider nicht gefunden werden.`) | |
var authorRoles = msg.member.roles | |
var userToPromote = msg.channel.guild.members.find(member => member.id == msg.mentions[0].id) | |
var providedRole = msg.channel.guild.roles.find(role => role.name == args.slice(1).join(" ")) | |
if (!providedRole) return bot.createMessage(msg.channel.id, `Fehler: Die Rolle "${args.slice(1).join(" ")}" konnte leider nicht gefunden werden.`) | |
if (userToPromote.roles.includes(providedRole.id)) return bot.createMessage(msg.channel.id, "Fehler: Der Nutzer besitzt die Rolle bereits.") | |
let rolePermissions = { //Key role can give user x each of it's value roles (role ids must be string because they are greater than 2^53 lol) | |
"755850280704278581": ["742339559639220284", "755841728950566994", "755842335467765881", "752826814656806942", "742339559639220284", "751100852814479480", "742339302780043325", "755842335467765881", "742339477451702334", "755864075623202896"], //Admin | |
"755864075623202896": ["742339477451702334"], | |
"755850280704278581": ["751100852814479480", "742339302780043325"], | |
"755842335467765881": ["752826814656806942"], | |
"755841728950566994": ["742339559639220284"] | |
} | |
let allowedRoles = [] //Array that gets populated by the loop below that will contain all roles the user is allowed to give others | |
//The loop is necessary because if a user has multiple key roles he would only have permissions for the values of the first key that gets found by includes() | |
Object.keys(rolePermissions).forEach((e, i) => { | |
if (authorRoles.includes(e)) { | |
Object.values(rolePermissions)[i].forEach(f => { //oh no a loop inside a loop | |
allowedRoles.push(f) | |
}) } }) | |
if (allowedRoles.includes(providedRole.id)) { //Permission granted | |
userToPromote.addRole(providedRole.id, `Promotion authorised by ${msg.author.username}#${msg.author.discriminator}`) | |
.then(() => { //Add Role! | |
bot.createMessage(msg.channel.id, `Dem Nutzer ${userToPromote.user.username}#${userToPromote.user.discriminator} wurde die Rolle ${providedRole.name} erfolgreich hinzugefügt.`) }) | |
.catch(err => { | |
return bot.createMessage(msg.channel.id, `Fehler beim Hinzufügen der Rolle.\n||Error: ${err}||`) }) //err.stack would return the full error stack if needed | |
} else { | |
return bot.createMessage(msg.channel.id, "Fehler: Es scheint als hättest du keine Berechtigung diese Rolle zu vergeben.") } | |
//Log the action | |
bot.createMessage(config.promoteLogChannel, { | |
embed: { | |
color: parseInt(config.color.padStart(6, '0'),16), | |
title: "Neue Beförderung", | |
description: `**${msg.author.username}#${msg.author.discriminator}** hat dem Nutzer **${userToPromote.user.username}#${userToPromote.user.discriminator}** die Rolle **${providedRole.name}** zugewiesen.`, | |
footer: { | |
text: 'Promote Plugin by 3urobeat#0975' //meinen Namen kannst du hier auch entfernen wenn du möchtest | |
}, | |
timestamp: new Date().toISOString() | |
}, | |
content: "||<@231827708198256642>||" | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment