Workaround Invalid Webhook Token Error

Recently, I have found that my game bot crashes because it throws Invalid Webhook Token Error when editing or defering an interaction. Looking at the logs, it seems that sometimes users take longer than 15 minutes to finish a match, which I understand it is the limit of a token since the first acknowledgement. I want to know what workaround do you suggest I could implement to allow users to play matches for longer than 15 minutes. I've been thinking about doing something like catching those failed interaction and getting the message content and then sending it in another message, but I don't know if it is possible or if there is better way to continue the game in the same message (just like we defer the messages, if there is a way to defer a webhook token to extend the limit).
6 Replies
d.js toolkit
d.js toolkitā€¢7mo 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! - āœ… Marked as resolved by OP
SEBAS
SEBASā€¢7mo ago
They interact with button/select menu interaction, every valid interaction is collected When one of those interaction is collected, it triggers a event that, by using a queue system, defers the interaction and edit the original message
d.js docs
d.js docsā€¢7mo ago
method ButtonInteraction#update() Updates the original message of the component on which the interaction was received on.
SEBAS
SEBASā€¢7mo ago
Ok, I'm going to try it Thanks I tested it using update instead of editReply, it seems that it still expires the token This is the error message I received: Invalid Webhook Token { "requestBody": { "files": [], "json": { "content": "Fall Ended", "tts": false, "embeds": [ { "color": 39423, "title": "Singles 2/3 Falls Match", "fields": [ { "name": "šŸŸ¢ SEBAS ", "value": "Health: 9%", "inline": true }, { "name": "šŸ”“ vamtibu", "value": "Health: 0%", "inline": true }, { "name": "Match Actions", "value": "šŸ¤¼ SEBAS launched an incredible dropkick to vamtibu, resulting in 19% damage.\nšŸ’€ vamtibu WAS ELIMINATED BY SEBAS\nšŸ›Žļø And the winner of this fall is...\nSEBAS!!! šŸŽ‰šŸŽ‰\nThe scores are:\nSEBAS: 1 fall\nvamtibu: 0 falls" } ] } ], "components": [ { "type": 1, "components": [ { "type": 2, "custom_id": "nextFall", "label": "šŸ‘ Next Fall? 0/2", "style": 1 }, { "type": 2, "custom_id": "leave", "label": "šŸƒ Leave", "style": 4 } ] } ] } }, "rawError": { "message": "Invalid Webhook Token", "code": 50027 }, "code": 50027, "status": 401, "method": "PATCH", "url": "https://discord.com/api/v10/webhooks/1164768291542269983/aW50ZXJhY3Rpb246MTE4MDE4NjY0NzEyODcxMTE4ODphVzU5dkZIYzBNSjJDaU5aWExIRTN2dzBWVmZJS2htMkUycEcwUlJQYXdkaFViQmJuVE5DanJ4Q0N4SlR2N3BERHZ1SzJTaHRua1VlRlNFRDdrSGlTTm5pMUNyaW16dUZiaXByelRvVmVRZlBYN294QjVDUEVuMFlhMVhZempjcA/messages/@original" } I call the update on every buttonInteraction I collect Sorry, had to replicate it again because I had the error stack turned off
SEBAS
SEBASā€¢7mo ago
You're right, the error happens after I call an editReply, which I call after the collector ends
SEBAS
SEBASā€¢7mo ago
Do you recommend me to change it to update the last collected interaction? Thank you, just tested and it works!