From 870ee2187d9732a2c457f74951e01b923baf3142 Mon Sep 17 00:00:00 2001 From: zekro Date: Mon, 8 Jan 2018 16:29:42 +0100 Subject: [PATCH] role tutorial --- main.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/main.js b/main.js index e1d9d5b..d47c591 100644 --- a/main.js +++ b/main.js @@ -48,5 +48,44 @@ client.on('message', (msg) => { }) +// https://discord.gg/uPsQQn + +const AUTOROLEID = "332164463186673666" + +client.on('guildMemberAdd', (memb) => { + + var role = memb.guild.roles.find(r => r.id == AUTOROLEID) + + if (role) { + memb.addRole(role).then(() => { + memb.send('', new Discord.RichEmbed().setColor(0x29B6F6).setDescription(`You got automatically assigned the role ${role.name}!`)) + }) + } + +}) + + +const PRES = { + "289901406985388033": "[MOD]", + "289901361951277056": "[ADMIN]" +} + + +client.on('guildMemberUpdate', (mold, mnew) => { + var guild = mnew.guild + if (mold.roles.array().length < mnew.roles.array().length) { + var role = mnew.roles.find(r => mold.roles.find(rold => rold.id == r.id) == null) + if (role.id in PRES) { + mnew.setNickname(`${PRES[role.id]} ${mnew.displayName}`) + } + } + else if (mold.roles.array().length > mnew.roles.array().length) { + var role = mold.roles.find(r => mnew.roles.find(rold => rold.id == r.id) == null) + if (role.id in PRES) { + mnew.setNickname(mnew.displayName.substr(PRES[role.id].length + 1)) + } + } +}) + client.login(config.token) \ No newline at end of file