REST randomly forgets token set with setToken
I'm using
@discordjs/rest
and Fastify
for HTTPS interactions. I'm initiating my REST client with:
The bot works fine for roughly a day before suddenly rejecting all requests with: Error: Expected token to be set for this request, but none was present
https://github.com/discordjs/discord.js/blob/65d1879c0ae2d8d820323d0d835b1e5e3d071e57/packages/rest/src/lib/RequestManager.ts#L364
I can not, for the life of me, figure out why rest
is consistently forgetting its token after roughly a day of operation. What am I missing?6 Replies
Restarting my app manually (via PM2) actually fixes the problem. But if it were to restart, it would just call this again - in which case it would have the token:
Everything that requires the REST client simply imports that ^. Works fine for roughly a day until every request rejects and I need to manually restart the PM2 process
hmmm @steveloper, we do have a code path that sets your token to null to protect you from a CF ban 👀
it happens if you somehow hit a 401
sadly this doesn't fire a debug event so you can't easily confirm if this is what happens
#justaddone
but if you could be so kind to listen to
RESTEvents.Response
and see if you get a 401 about one request before the one that causes the throw
that'd be lovely
I'm particularly interested in the 2nd object you get in that event - the Response object, I want to see what route/method it is that causes your token to resetI will add that now, but it will take ~a day to occur
yup yup
feel free to @ me back once it happens