-
Notifications
You must be signed in to change notification settings - Fork 153
Incorrectly adding / removing roles #289
Comments
listen for errors with bot.addToRole({
xx: xx,
yy: yy
}, function(err){
console.log(err)
}) Im betting you're getting ratelimited, but I've never assigned roles as fast as you so I can't be sure. |
{ ResponseError: Could not add role |
how fix it ? |
can be somehow you can find out what roles the user now has? |
and then delete the currently selected roles and assign new ones |
There are three endpoints in the API for assigning roles to members.
discord.io uses endpoints 1 and 2, but for assigning many roles at once it's easier to use endpoint 3. Unfortunately discord.io does not expose a method for this endpoint, so we have to manually make a request to the API.
For the role array, all previous roles will be wiped and replaced with that array. Therefore you should adapt your code to, instead of performing bot.addToRole, simply add that role ID to an empty array. Then after all your This way you are only making one request, which should be (a) faster, (b) more reliable, and (c) not hit the rate limit errors. |
I do not understand until the end how to order me to implement your code :( Thanks for the help, but I can not adapt to my code, I'm new at this |
request({ var kill; } var damage; |
before starting the code, I delete all the roles that I can get further
bot.removeFromRole({
serverID: id server,
userID: id user,
roleID: id role,
});
.....
After that, I have a condition:
if (avgStats.avgDamageDealt > 250) {
bot.addToRole({
serverID: '482986292997783562',
userID: cmd.discordUser.id,
roleID: '485142162262982666', // 250+
});
} else if (avgStats.avgDamageDealt > 200) {
bot.addToRole({
serverID: '482986292997783562',
userID: cmd.discordUser.id,
roleID: '485142170844659730', // 200+
});
}
if (avgStats.avgKills > 2) {
bot.addToRole({
serverID: '482986292997783562',
userID: cmd.discordUser.id,
roleID: '484902728976433152', // 2+
});
}
else if (avgStats.avgKills > 1.5) {
bot.addToRole({
serverID: '482986292997783562',
userID: cmd.discordUser.id,
roleID: '484854918348406787', // 1.5+
});
If you write a command in a discord chat !Stats.
The bot must first delete all roles and assign a new one depending on the avgStats.avgDamageDealt .
But the bot sometimes does not delete or add.
I have already seen in the problems of Discord and this situation and nothing has changed.
The text was updated successfully, but these errors were encountered: