unknown webhook errors discord http bot

Hey guys, I have a http only bot running on a cf worker and im running into random Unknown webhook problems, mainly for my /meme command, and I have no idea what's wrong or where to go to fix it. Here's the code for my /meme command: https://sourceb.in/yrwYOIxtyS The command "handler": https://sourceb.in/pzY6NMCBQt In my index.ts I just have this https://sourceb.in/n6o9OX2kRH which is just a switch case over all of the types, simple stuff. I believe it's because im trying to "editReply" before the deferReply has "resolved", but im wondering what I can actually do to help this. I have a button too, which this happens with, basically the same code though. Thanks.
20 Replies
Walshy
Walshy2mo ago
what's the exact error?
gwapes
gwapes2mo ago
From discord it’s just the code and the message being unknown webhook, let me grab it again { message: 'Unknown Webhook', code: 10015 } Idk if I’ve done something funky in my project, probably that
Walshy
Walshy2mo ago
that sounds like your webhook url is invalid
gwapes
gwapes2mo ago
It doesnt happen all of the time either. One of the mods in ddevs said it could be the worker taking too long to respond but idk If it was invalid it would happen all the time?
Walshy
Walshy2mo ago
const webhookUrl = https://discord.com/api/v10${Routes.webhookMessage(env.discord_application_id, interaction.token, '@original')};
so i would print this out and check what it's returning
gwapes
gwapes2mo ago
I removed the “env.discord_application_id” and pasted it with my app id for testing and got the same thing, so I’m sure it isn’t that Routes is from discord-api-types to make the url (log) https://discord.com/api/v10/webhooks/1170832155958587423/aW50ZXJhY3Rpb246MTI3MzcxMTI5NjI1NjI4MjcwNTpkUHFxQkFKdmFYTmEyYzE2cHlHZDF4d285QjBMTnZNRmRpWFdRcFRSSlA4UGRzYlhNOEpZSHh1Q2QwdDcyVjN1Zm5wMUJUd0lnZlFvZzVCajBjUVNMUDNhRTR4WWtxd1pEVnp6V1VSd2hna2x2cDJPN2ZJalZGY
(error) Error response from Discord: { message: 'Unknown Webhook', code: 10015 }
POST https://gwapes.com/interactions - Ok @ 15/08/2024, 19:34:36
(log) Button
(log) aW50ZXJhY3Rpb246MTI3MzcxMTQ2MDc0NDE3MTY1MjpUaE1BaXNYeXBBOXRRckxUaVlvbUI0Y2Z0cGJKdGZLR3VvN1o5Q0lBUE1KdWhOcHd5d0w4a2RHSmNKZ3B4anVhWnRPRXNQUzBMaFJqSnVFbVVOdGg3VkxGcXNYMjA0YXhkY2x6Z2l1eVhXb29PT3owWWNjanVyRjVlNkFSU2dHYg
(log) https://discord.com/api/v10/webhooks/1170832155958587423/aW50ZXJhY3Rpb246MTI3MzcxMTQ2MDc0NDE3MTY1MjpUaE1BaXNYeXBBOXRRckxUaVlvbUI0Y2Z0cGJKdGZLR3VvN1o5Q0lBUE1KdWhOcHd5d0w4a2RHSmNKZ3B4anVhWnRPRXNQUzBMaFJqSnVFbVVOdGg3VkxGcXNYMjA0YXhkY2x6Z2l1eVhXb29PT3owWWNjanVyRjVlNkFSU2dHYg/messages/@original
POST https://gwapes.com/interactions - Ok @ 15/08/2024, 19:34:38
(log) Button
(log) aW50ZXJhY3Rpb246MTI3MzcxMTQ2NjU5NTIyNTYwMDpNdTY1ejQ3cjdkaEx3OExtRzNieUt4aktKZ0hpOFloWHlmNm56RElPZDFwcDd3bEJpNW9WTHZiOHFKZXlvTHFJMmlCMUFZZFQ2U0Z0ZWVRcmEwSVVlUHdjN3JmdDB0VFdPUGx5amJFbHJpZFVkUDRybzM3VkNONzZEWlpLRGRTMg
(log) https://discord.com/api/v10/webhooks/1170832155958587423/aW50ZXJhY3Rpb246MTI3MzcxMTQ2NjU5NTIyNTYwMDpNdTY1ejQ3cjdkaEx3OExtRzNieUt4aktKZ0hpOFloWHlmNm56RElPZDFwcDd3bEJpNW9WTHZiOHFKZXlvTHFJMmlCMUFZZFQ2U0Z0ZWVRcmEwSVVlUHdjN3JmdDB0VFdPUGx5amJFbHJpZFVkUDRybzM3VkNONzZEWlpLRGRTMg/messages/@original
(error) Error response from Discord: { message: 'Unknown Webhook', code: 10015 }
POST https://gwapes.com/interactions - Ok @ 15/08/2024, 19:34:36
(log) Button
(log) aW50ZXJhY3Rpb246MTI3MzcxMTQ2MDc0NDE3MTY1MjpUaE1BaXNYeXBBOXRRckxUaVlvbUI0Y2Z0cGJKdGZLR3VvN1o5Q0lBUE1KdWhOcHd5d0w4a2RHSmNKZ3B4anVhWnRPRXNQUzBMaFJqSnVFbVVOdGg3VkxGcXNYMjA0YXhkY2x6Z2l1eVhXb29PT3owWWNjanVyRjVlNkFSU2dHYg
(log) https://discord.com/api/v10/webhooks/1170832155958587423/aW50ZXJhY3Rpb246MTI3MzcxMTQ2MDc0NDE3MTY1MjpUaE1BaXNYeXBBOXRRckxUaVlvbUI0Y2Z0cGJKdGZLR3VvN1o5Q0lBUE1KdWhOcHd5d0w4a2RHSmNKZ3B4anVhWnRPRXNQUzBMaFJqSnVFbVVOdGg3VkxGcXNYMjA0YXhkY2x6Z2l1eVhXb29PT3owWWNjanVyRjVlNkFSU2dHYg/messages/@original
POST https://gwapes.com/interactions - Ok @ 15/08/2024, 19:34:38
(log) Button
(log) aW50ZXJhY3Rpb246MTI3MzcxMTQ2NjU5NTIyNTYwMDpNdTY1ejQ3cjdkaEx3OExtRzNieUt4aktKZ0hpOFloWHlmNm56RElPZDFwcDd3bEJpNW9WTHZiOHFKZXlvTHFJMmlCMUFZZFQ2U0Z0ZWVRcmEwSVVlUHdjN3JmdDB0VFdPUGx5amJFbHJpZFVkUDRybzM3VkNONzZEWlpLRGRTMg
(log) https://discord.com/api/v10/webhooks/1170832155958587423/aW50ZXJhY3Rpb246MTI3MzcxMTQ2NjU5NTIyNTYwMDpNdTY1ejQ3cjdkaEx3OExtRzNieUt4aktKZ0hpOFloWHlmNm56RElPZDFwcDd3bEJpNW9WTHZiOHFKZXlvTHFJMmlCMUFZZFQ2U0Z0ZWVRcmEwSVVlUHdjN3JmdDB0VFdPUGx5amJFbHJpZFVkUDRybzM3VkNONzZEWlpLRGRTMg/messages/@original
https://sourceb.in/ebNpFe9bQ4 this is my entire router.post for interactions too if it helps
D Trombett
D Trombett2mo ago
What do you see on Discord? Do you see the message like "App is thinking..." or something similar?
gwapes
gwapes2mo ago
Yh, it does successfully defer and then I get the unknown webhook error
D Trombett
D Trombett2mo ago
The fact that you're saying that it sometimes works confuses me I think that something is wrong with the fetch calls Like, you're not always passing the content type header and never passing your token tbh I would suggest you using @discordjs/rest to make API calls to discord as it handles everything What I do is creating a rest.ts file with this content (the hash and handler options were required to make it work in Workers, not sure if they've fixed it now):
import { REST } from "@discordjs/rest";
import { APIVersion } from "discord-api-types/v10";

export const rest = new REST({
version: APIVersion,
hashSweepInterval: 0,
handlerSweepInterval: 0,
})
import { REST } from "@discordjs/rest";
import { APIVersion } from "discord-api-types/v10";

export const rest = new REST({
version: APIVersion,
hashSweepInterval: 0,
handlerSweepInterval: 0,
})
And at the start of the fetch server handler I call rest.setToken(env.DISCORD_TOKEN). Then I use the rest whenever I need it by importing it, like in my ping command:
await rest.patch(
Routes.webhookMessage(interaction.application_id, interaction.token),
{
body: {
content: `🏓 **Pong!** ...`,
} satisfies RESTPatchAPIWebhookWithTokenMessageJSONBody,
},
)
await rest.patch(
Routes.webhookMessage(interaction.application_id, interaction.token),
{
body: {
content: `🏓 **Pong!** ...`,
} satisfies RESTPatchAPIWebhookWithTokenMessageJSONBody,
},
)
gwapes
gwapes2mo ago
You don’t need to pass the token for an editReply, https://github.com/discordjs/discord.js/blob/main/packages/discord.js/src/structures/Webhook.js#L341 Ig the only thing I can see now is that they pass the interaction id?
GitHub
discord.js/packages/discord.js/src/structures/Webhook.js at main · ...
A powerful JavaScript library for interacting with the Discord API - discordjs/discord.js
gwapes
gwapes2mo ago
Nvm they don’t it’s still the app id
gwapes
gwapes2mo ago
GitHub
discord.js/packages/discord.js/src/structures/InteractionWebhook.js...
A powerful JavaScript library for interacting with the Discord API - discordjs/discord.js
gwapes
gwapes2mo ago
I mean I can try using that, I was just going more simply and using fetch
D Trombett
D Trombett2mo ago
Mmh, it's strange because I just tried and it gave me an error about not passing the token
gwapes
gwapes2mo ago
With the editReply route? I mean either way, that’s not my issue since it doesn’t error either unauthorised I mean I can pop it in there I need to spin up some code using a library or something, my handling is probably wrong Also would be good to point out that it only ever happens when you spam it. It seems to happen in servers more often then it does in the dms of the bot
Want results from more Discord servers?
Add your server