discordgo icon indicating copy to clipboard operation
discordgo copied to clipboard

ChannelMessagesPinned uses wrong ratelimit bucket

Open riking opened this issue 4 years ago • 2 comments

The ChannelMessagesPinned function uses EndpointChannelMessagesPins(channelID) as its ratelimit bucket. https://github.com/bwmarrin/discordgo/blob/8416350/restapi.go#L1693

This is incorrect. The ratelimit for pins requests is shared across all channels and guilds.

I recommend replacing the bucket with a constant of "/pins/global".

riking avatar Nov 17 '19 06:11 riking

I wrote a small program that logs the response headers to prove this: https://github.com/riking/AutoDelete/blob/master/cmd/pinsHeaders.go

It consistently prints "X-Ratelimit-Bucket: 29438e9be9d5f3f082da200ec5a36e41" no matter what channel I request, plus:

X-Ratelimit-Limit: 1
X-Ratelimit-Remaining: 0
X-Ratelimit-Reset: <timestamp in near future>
X-Ratelimit-Reset-After: 5

riking avatar Nov 17 '19 06:11 riking

This is the code currently in use:

body, err = c.bot.s.RequestWithBucketID("GET", discordgo.EndpointChannelMessagesPins(c.ChannelID), nil, "/custom/pinsGlobal")

riking avatar Oct 01 '21 20:10 riking