Last active
July 10, 2020 07:25
-
-
Save aDu/03703703bfe23ce102d3585346c87cec to your computer and use it in GitHub Desktop.
Eris react to role bot (using https://github.com/abalabahaha/eris/). Gives the Guild Discord role when reacting (removes the role if you already had the role).
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
var emojiToRole = { | |
'β€οΈ': '730969029392597014', | |
'π§‘': '550097270906028042', | |
'π': '730970455158292582', | |
'π': '730970493527654531', | |
'π': '526038406182993941', | |
'π': '541054776440520744', | |
'π€': '730970538335404033', | |
'π€': '730982363605237800', | |
} | |
var emojiRoles = new Set(Object.values(emojiToRole)) | |
var rolesMessageId = '730980512746962975' | |
var updateRoles = function (message, emoji, userID) { | |
if (message.id == rolesMessageId) { | |
var guild = message.channel.guild | |
guild.fetchMembers({ | |
userIDs: [userID], | |
limit: 1 | |
}).then(members => { | |
var member = members[0] | |
// Find previous role and remove all related roles | |
var newRoles = member.roles.filter(function(el) { | |
return !emojiRoles.has(el) | |
}) | |
// Add the new role if it didn't have it before | |
var newRole = emojiToRole[emoji.name]; | |
if (!member.roles.includes(newRole)) { | |
newRoles.push(newRole) | |
} | |
guild.editMember(userID, { | |
roles: newRoles | |
}) | |
}) | |
} | |
}; | |
bot.on('messageReactionAdd', updateRoles) | |
bot.on('messageReactionRemove', updateRoles) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment