Skip to content

Instantly share code, notes, and snippets.

@aDu
Last active July 10, 2020 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aDu/03703703bfe23ce102d3585346c87cec to your computer and use it in GitHub Desktop.
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).
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