discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

Roles taking 10 minutes to add if at all #4655

Closed lostful closed 4 years ago

lostful commented 4 years ago

So when I make the bot add a role with some code, it adds it 5 minutes later. Does anyone know why? I am not ratelimited and I have no restrictions or anything. There are also no errors.

Here is my code:

    const banned = message.guild.roles.cache.get("729298310480789525");

    user.roles.add(banned);
    db.set(`banned_${user.id}`, true);
    db.set(`banned_${user.id}_reason`, reason);
    user.send(embed);
    message.guild.channels.cache.get("729300545201766430").send(embed2);
    message.channel.send(":white_check_mark:").then(message => { message.delete({ timeout: 5000 }) });

Further details:

NotSugden commented 4 years ago

are you sure you aren't ratelimited? have you checked the Client#ratelimit event? this sounds like a ratelimit issue

lostful commented 4 years ago

I am definitely not ratelimited. I have tried it with multiple bots all on 3 different hosts.

xonrsoftware commented 4 years ago

I have same problem, but with channels. I think it's problem with performance degradation on some Discord API proxy servers. Request is hanging. With different bot processed immediately; try to create new bot, if you have it just for several servers.

I don't know why timeout not occurred via Discord.js https://github.com/discordjs/discord.js/blob/2b6e6d86310a9f9fc4293c2f76f37690db9003e4/src/rest/APIRequest.js#L54-L62 Hanging for more than 1 min (sometimes 5-10-15). Latest commit: 2b6e6d86310a9f9fc4293c2f76f37690db9003e4

const Discord = require('discord.js');
const client = new Discord.Client();

client.on('error', (error) => {
    console.log("Error d.js!");
});

process.on('unhandledRejection', function (reason, p) {
    console.log("Possibly Unhandled Rejection at: Promise ", p, " reason: ", reason);
});
process.on('uncaughtException', function (err) {
    console.log('Caught exception: ', err);
});

client.on('ready', async () => {
    await (await client.channels.fetch('0000')).setName("tttt");

    console.log("Done.");

});

client.on('ratelimit', (rateLimitInfo) => {
    console.log("RateLimit!");
});
client.login('000');
monbrey commented 4 years ago

@AkaEthan101 different bots and hosts are irrelevant here - rate limits are in relation to the rate at which your bot, any of the bots, makes requests. If any of your three bots are attempting to modify roles too quickly, exceeding the rate limit, the behaviour you observed will occur.

@xonrsoftware Discord changed the rate limits on editing channel names and topic to 2/10 minutes. Any attempt to edit the channel more often than this will be queued by discord.js until the rate limit timeout duration is complete.

xonrsoftware commented 4 years ago

@monbrey, where it's officially announced? Can't find.

SpaceEEC commented 4 years ago

See #4327

qpn6ph9q commented 4 years ago

I have a bot managing a 42,000 member discord. This problem also occurs, but it is very rare. It has only happened 5 times in the last 7,000 role assignments.

The last event happened this morning. Noteably this was a roles.remove request rather than roles.add.

My suspicion is a caching issue, but I am not familiar with the caching strategy to come to any firm conclusions yet. In the meantime I will keep collecting data on this.

lostful commented 4 years ago

@monbrey It's not ratelimits though because I've been waiting for 2 days and it's still not working..

qpn6ph9q commented 4 years ago

We've just had 3 new occurrences of this coupled with a spike in new members to the server. 2k new members. it seems to occur more in times of peak API load

lostful commented 4 years ago

Panic over, turns out as though I was indeed ratelimited. This was due to a loop running every 30 seconds that had a lot of code inside.