Skip to content
This repository has been archived by the owner on Mar 27, 2021. It is now read-only.

Commit

Permalink
role tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
zekro committed Jan 8, 2018
1 parent 58b5146 commit 870ee21
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 870ee21

Please sign in to comment.