Discord.Net icon indicating copy to clipboard operation
Discord.Net copied to clipboard

[Bug]: Rate limited while calling ModifyAsync on Message

Open steffenhauge opened this issue 3 years ago • 8 comments

Check The Docs

  • [X] I double checked the docs and couldn't find any useful information.

Verify Issue Source

  • [X] I verified the issue was caused by Discord.Net.

Check your intents

  • [X] I double checked that I have the required intents.

Description

Im trying to update messages in a channel but I keep getting rate limited. Even though im wating 5 seconds between calls and the rate-limit information tells me there is avaliable requests left. (I might be wrong about this?)

Using somecode from: https://github.com/discord-net/Discord.Net/blob/dev/docs/guides/concepts/ratelimits.md I printed out the rate-limit information for each request.

Reading the Discord Developer Portal about rate-limits: https://github.com/discord-net/Discord.Net/blob/dev/docs/guides/concepts/ratelimits.md Mentions "Exceeded Resource Rate Limit Response" where RateLimit-Remaining is greater than 0 but still being rate-limited.

Is this the issue im running into here? And if so, can I do anything about it?

Version

3.7.2

Working Version

No response

Logs

2022-07-02 18:41:07.154 +02:00 [INF] Calling ModifyAsync count: 1
2022-07-02 18:41:07.433 +02:00 [INF] Rest: PATCH channels/742473571053469807/messages/992782680146059294: 252,3 ms
2022-07-02 18:41:07.435 +02:00 [DBG] Gateway: Received Dispatch (MESSAGE_UPDATE)
2022-07-02 18:41:07.442 +02:00 [INF] 
IsGlobal:False
Limit:5
Remaining:4
RetryAfter:
Reset:02-07-2022 16:41:13 +00:00
ResetAfter:00:00:05
Bucket:da101873bd9ceb21138638aa25f33cb1
Lag:-00:00:00.5666488
Endpoint:channels/742473571053469807/messages/992782680146059294
2022-07-02 18:41:12.444 +02:00 [INF] Calling ModifyAsync count: 2
2022-07-02 18:41:12.699 +02:00 [INF] Rest: PATCH channels/742473571053469807/messages/992782680146059294: 253,09 ms
2022-07-02 18:41:12.699 +02:00 [INF] 
IsGlobal:False
Limit:5
Remaining:4
RetryAfter:
Reset:02-07-2022 16:41:18 +00:00
ResetAfter:00:00:05
Bucket:da101873bd9ceb21138638aa25f33cb1
Lag:-00:00:00.3009295
Endpoint:channels/742473571053469807/messages/992782680146059294
2022-07-02 18:41:12.702 +02:00 [DBG] Gateway: Received Dispatch (MESSAGE_UPDATE)
2022-07-02 18:41:17.707 +02:00 [INF] Calling ModifyAsync count: 3
2022-07-02 18:41:17.906 +02:00 [DBG] Gateway: Received Dispatch (MESSAGE_UPDATE)
2022-07-02 18:41:17.906 +02:00 [INF] Rest: PATCH channels/742473571053469807/messages/992782680146059294: 197,09 ms
2022-07-02 18:41:17.906 +02:00 [INF] 
IsGlobal:False
Limit:5
Remaining:4
RetryAfter:
Reset:02-07-2022 16:41:23 +00:00
ResetAfter:00:00:05
Bucket:da101873bd9ceb21138638aa25f33cb1
Lag:-00:00:00.0935925
Endpoint:channels/742473571053469807/messages/992782680146059294
2022-07-02 18:41:22.918 +02:00 [INF] Calling ModifyAsync count: 4
2022-07-02 18:41:23.193 +02:00 [INF] 
IsGlobal:False
Limit:5
Remaining:4
RetryAfter:3
Reset:02-07-2022 16:41:29 +00:00
ResetAfter:00:00:05
Bucket:da101873bd9ceb21138638aa25f33cb1
Lag:-00:00:00.8068205
Endpoint:channels/742473571053469807/messages/992782680146059294
2022-07-02 18:41:23.213 +02:00 [WRN] Rest: Rate limit triggered: PATCH channels/742473571053469807/messages/992782680146059294 (Bucket: da101873bd9ceb21138638aa25f33cb1)
2022-07-02 18:41:23.412 +02:00 [WRN] Rest: Rate limit triggered: PATCH channels/742473571053469807/messages/992782680146059294 (Bucket: da101873bd9ceb21138638aa25f33cb1)
2022-07-02 18:41:23.412 +02:00 [INF] 
IsGlobal:False
Limit:5
Remaining:4
RetryAfter:2
Reset:02-07-2022 16:41:29 +00:00
ResetAfter:00:00:05
Bucket:da101873bd9ceb21138638aa25f33cb1
Lag:-00:00:00.5873884
Endpoint:channels/742473571053469807/messages/992782680146059294
2022-07-02 18:41:23.414 +02:00 [INF] Rest: Preemptive Rate limit triggered: PATCH channels/742473571053469807/messages/992782680146059294 (Bucket: da101873bd9ceb21138638aa25f33cb1)
2022-07-02 18:41:26.450 +02:00 [DBG] Gateway: Received Dispatch (MESSAGE_UPDATE)
2022-07-02 18:41:26.457 +02:00 [INF] Rest: PATCH channels/742473571053469807/messages/992782680146059294: 3537,53 ms
2022-07-02 18:41:26.457 +02:00 [INF] 
IsGlobal:False
Limit:5
Remaining:4
RetryAfter:
Reset:02-07-2022 16:41:32 +00:00
ResetAfter:00:00:05
Bucket:da101873bd9ceb21138638aa25f33cb1
Lag:-00:00:00.5428466
Endpoint:channels/742473571053469807/messages/992782680146059294

Sample

SocketTextChannel channel = guild.GetTextChannel(dbGuild.LeaderboardChannelId);
IMessage msg = await channel.GetMessageAsync(prevEmbed.MessageId);
for (int i = 0; i < 10; i++)
{
  var options = new RequestOptions()
  {
    RatelimitCallback = MyRatelimitCallback
  };
  _logger.LogInformation($"Calling ModifyAsync count: {i + 1}");
  await ((IUserMessage)msg).ModifyAsync(x =>
  {
    x.Embed = embed;
  }, options: options);
  // Wait before next call
  await Task.Delay(TimeSpan.FromSeconds(5));
}

Packages

None

steffenhauge avatar Jul 02 '22 16:07 steffenhauge

@steffenhauge you can edit a channel by a bot every 5th minute.

killerfrienddk avatar Jul 02 '22 17:07 killerfrienddk

@steffenhauge you can edit a channel by a bot every 5th minute.

But im not editing the channel?

Im changing a message in a channel?

steffenhauge avatar Jul 02 '22 17:07 steffenhauge

It seems try retry way to often also?

Some other messages from earlier

2022-07-02 16:35:20.605 +02:00 [WRN] Rest: Rate limit triggered: PATCH channels/742473571053469807/messages/992782712446390286 (Bucket: da101873bd9ceb21138638aa25f33cb1)
2022-07-02 16:35:20.833 +02:00 [WRN] Rest: Rate limit triggered: PATCH channels/742473571053469807/messages/992782712446390286 (Bucket: da101873bd9ceb21138638aa25f33cb1)
2022-07-02 16:35:21.043 +02:00 [WRN] Rest: Rate limit triggered: PATCH channels/742473571053469807/messages/992782712446390286 (Bucket: da101873bd9ceb21138638aa25f33cb1)
2022-07-02 16:35:21.270 +02:00 [WRN] Rest: Rate limit triggered: PATCH channels/742473571053469807/messages/992782712446390286 (Bucket: da101873bd9ceb21138638aa25f33cb1)
2022-07-02 16:35:21.445 +02:00 [WRN] Rest: Rate limit triggered: PATCH channels/742473571053469807/messages/992782712446390286 (Bucket: da101873bd9ceb21138638aa25f33cb1)

steffenhauge avatar Jul 02 '22 17:07 steffenhauge

This should be the ratelimits but you should be able to edit a message every second pr channel. image

killerfrienddk avatar Jul 02 '22 17:07 killerfrienddk

Yeah idk it's weird.

If i sleep 2 seconds before calling GetMessageAsync and then sleep 5 Seconds before calling ModifyAsync

Then it seems to work fine

steffenhauge avatar Jul 02 '22 17:07 steffenhauge

Hello there,

it's been a while, I know, but did you perhaps find another possibility than to let it sleep 7 seconds each time? I've recently run into the exact same problem that even though I am waiting 5 seconds between each call, I get the rate limit in my face with way to many requests.

Best regards tasu

tasutafat avatar May 30 '23 10:05 tasutafat

Hello there,

it's been a while, I know, but did you perhaps find another possibility than to let it sleep 7 seconds each time? I've recently run into the exact same problem that even though I am waiting 5 seconds between each call, I get the rate limit in my face with way to many requests.

Best regards tasu

No. Im still doing a fixed delay after each operation.

steffenhauge avatar May 30 '23 10:05 steffenhauge