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
- 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 OPThey 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
ButtonInteraction#update()
Updates the original message of the component on which the interaction was received on.
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
You're right, the error happens after I call an editReply, which I call after the collector ends
Do you recommend me to change it to update the last collected interaction?
Thank you, just tested and it works!