REST Crash

I am using the REST class of discord.js to edit messages with the interaction token, I am using .patch on the webhookMessage endpoint. It normally works, but I sometimes get an invalid token error which crashes the entire server, even though the request is awaited and in a try catch block. What is the cause of this, are there any solutions? Ty!
10 Replies
d.js toolkit
d.js toolkit6mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Barnuss
BarnussOP6mo ago
Sure! The error is: home/container/node_modules/@discordjs/rest/dist/index.js:730 throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData); ^ DiscordAPIError[50027]: Invalid Webhook Token at handleErrors (/home/container/node_modules/@discordjs/rest/dist/index.js:730:13)  at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async SequentialHandler.runRequest (/home/container/node_modules/@discordjs/rest/dist/index.js:1133:23) at async SequentialHandler.queueRequest (/home/container/node_modules/@discordjs/rest/dist/index.js:963:14) at async _REST.request (/home/container/node_modules/@discordjs/rest/dist/index.js:1278:22) at async addUser (/home/container/commands/multiGame.js:201:7) { requestBody: { files: undefined, json: { embeds: [ // not relevant ] } }, rawError: { message: 'Invalid Webhook Token', code: 50027 }, code: 50027, status: 401, method: 'PATCH', url: 'https://discord.com/api/v10/webhooks/1225076420980641882/aW50ZXJhY3Rpb246MTI2NDkwNzc2NTI5MDEwNjkwMDpOQnREa2lkSEdER2dmSnU0VkdPN1pRbWJrZDF0dUhhY2wxTTg0SHRzQVphTXMxMmxDTENtcE1LdVZpM0xGUUtkaDdqRHBSbWh4WnpuU0pVeEdDVGd5OENabUhDa2NJSlZLVVcxejJzQUJpbVVpZmdmQ2lUN0hLbWFMdXNjVGNkQg/messages/@original' }
treble/luna
treble/luna6mo ago
are you trying to edit the reply after 15 minutes (of the original interaction happening)?
Barnuss
BarnussOP6mo ago
could be the case actually, since it is a rare one thanks but still, i don't get how the server crashes :OMEGAlul: it's awaited and in try catch Alrighty: client.on("interactionCreate", async (interaction) => { if (!interaction.isButton()) return; if (interaction.customId !== "single_guess_confirm") return; try { // ... const discordApi = new REST().setToken(client.token); await discordApi.patch(Routes.webhookMessage(client.user.id, token), { files: [{ data: finalMapImage, name: "map.png" }], body: { // not relevant, embed with buttons }, }); // ... } catch (error) { console.error(error); } });
pat
pat6mo ago
where are you getting token and is there a reason you can't just use interaction.editReply instead nvm where you get token is probably irrelevant
Barnuss
BarnussOP6mo ago
the original message has a button that replies with an ephemeral containing yet another button, which edits the original if that makes sense lol
pat
pat6mo ago
oh so you're using rest because you don't have the context of the original interaction anymore you wouldn't happen to be getting token from the current interaction though would you? that would only let you edit the ephemeral message you're sending Would it be easier to get that messageId you're trying to edit via interaction.message.reference.messageId and edit it with interaction.channel.messages.edit(messageId, options) since it's non-ephemeral(?)
Barnuss
BarnussOP6mo ago
Hmmm yeah, I intend it to be a user app though and that would lead to permission issues Biut thanks
pat
pat6mo ago
well you need to keep context of the first interaction then, since the token for both replies is going to be different
Barnuss
BarnussOP6mo ago
It's a button press event Sorry, line 201 is the one starting with await discordApi.patch(...) But I might just consider a whole new approach to this, something without rest Ahh yes I’ll use the built in WebhookClient, thanks for the help though :) Gotcha, thank you
Want results from more Discord servers?
Add your server