Bot crashes: invalid webhook token

Hi my bot crashes after running a command that takes about 15 minutes to finish? The command updates the message according to the 'game state'. this is the error code
error: Uncaught (in promise) DiscordAPIError[50027]: Invalid Webhook Token
at handleErrors (file:///C:/Users/Jurn Wubben/AppData/Local/deno/npm/registry.npmjs.org/@discordjs/rest/2.4.0/dist/index.js:727:13)
at eventLoopTick (ext:core/01_core.js:175:7)
at async SequentialHandler.runRequest (file:///C:/Users/Jurn Wubben/AppData/Local/deno/npm/registry.npmjs.org/@discordjs/rest/2.4.0/dist/index.js:1128:23)
at async SequentialHandler.queueRequest (file:///C:/Users/Jurn Wubben/AppData/Local/deno/npm/registry.npmjs.org/@discordjs/rest/2.4.0/dist/index.js:959:14)
at async _REST.request (file:///C:/Users/Jurn Wubben/AppData/Local/deno/npm/registry.npmjs.org/@discordjs/rest/2.4.0/dist/index.js:1272:22)
at async InteractionWebhook.editMessage (file:///C:/Users/Jurn Wubben/AppData/Local/deno/npm/registry.npmjs.org/discord.js/14.16.3/src/structures/Webhook.js:341:15)
at async ButtonInteraction.editReply (file:///C:/Users/Jurn Wubben/AppData/Local/deno/npm/registry.npmjs.org/discord.js/14.16.3/src/structures/interfaces/InteractionResponses.js:162:17)
at async file:///C:/Users/Jurn Wubben/Documents/DCBot/src/commands/utility/coc.ts:570:5
error: Uncaught (in promise) DiscordAPIError[50027]: Invalid Webhook Token
at handleErrors (file:///C:/Users/Jurn Wubben/AppData/Local/deno/npm/registry.npmjs.org/@discordjs/rest/2.4.0/dist/index.js:727:13)
at eventLoopTick (ext:core/01_core.js:175:7)
at async SequentialHandler.runRequest (file:///C:/Users/Jurn Wubben/AppData/Local/deno/npm/registry.npmjs.org/@discordjs/rest/2.4.0/dist/index.js:1128:23)
at async SequentialHandler.queueRequest (file:///C:/Users/Jurn Wubben/AppData/Local/deno/npm/registry.npmjs.org/@discordjs/rest/2.4.0/dist/index.js:959:14)
at async _REST.request (file:///C:/Users/Jurn Wubben/AppData/Local/deno/npm/registry.npmjs.org/@discordjs/rest/2.4.0/dist/index.js:1272:22)
at async InteractionWebhook.editMessage (file:///C:/Users/Jurn Wubben/AppData/Local/deno/npm/registry.npmjs.org/discord.js/14.16.3/src/structures/Webhook.js:341:15)
at async ButtonInteraction.editReply (file:///C:/Users/Jurn Wubben/AppData/Local/deno/npm/registry.npmjs.org/discord.js/14.16.3/src/structures/interfaces/InteractionResponses.js:162:17)
at async file:///C:/Users/Jurn Wubben/Documents/DCBot/src/commands/utility/coc.ts:570:5
and it crashes in this part of the code
const message = await interaction.reply({...clashMessage({
handle: clash,
langs,
modes,
players: [{ nickname: "loading..." }],
started: false,
}, interaction.user.id)});

// message.startThread({
// name: "Clash of Code",
// reason: "Discuss your coc here."
// })

await clashEventManager(clash, async (data) => {
await message.edit(clashMessage(data, interaction.user.id)); // CRASHES HERE
});
const message = await interaction.reply({...clashMessage({
handle: clash,
langs,
modes,
players: [{ nickname: "loading..." }],
started: false,
}, interaction.user.id)});

// message.startThread({
// name: "Clash of Code",
// reason: "Discuss your coc here."
// })

await clashEventManager(clash, async (data) => {
await message.edit(clashMessage(data, interaction.user.id)); // CRASHES HERE
});
the clahsEventManager is a function that runs the callback when there's a message received via socket.io I'll also upload my full code later.
20 Replies
d.js toolkit
d.js toolkit2mo 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
jsw
jswOP2mo ago
jsw
jswOP2mo ago
clashEventManager is at 218 and the crash happends at 570
treble/luna
treble/luna2mo ago
an interaction webhook stays valid for 15 minutes after that it will error with that
jsw
jswOP2mo ago
How do i get a new webhook or fix this? Do i have to fetch the message each time and edit it?
treble/luna
treble/luna2mo ago
you would need a new interaction if you have replied before, which i cant see, use a pastebin, you can edit the interaction messages yes, as long as it is not ephemeral
jsw
jswOP2mo ago
https://gist.github.com/jsw08/8a239f8ddbd71f3ba1bbc29f4cee4e2a i reply once to the interaction, and try to edit that message every time the websocket gives an update the game takes around 15 minutes, and can take up to 5-10 minutes before the game starts so max 25 minutes, usually ~16 Other files are at https://github.com/jsw08/DCBot/tree/52-coc-socketio-integration haven't pushed this one yet.
treble/luna
treble/luna2mo ago
you're better off using a regular message then
jsw
jswOP2mo ago
So just replying to my own message?
treble/luna
treble/luna2mo ago
both should just work, but you wont be able to edit it through the interaction webhook, you will need to edit the message like you would for a regular message which doesnt work if the message is ephemeral which it is as far as i can see so you would need to make it non ephemeral
jsw
jswOP2mo ago
Thanks! I had another (relatively small) issue, can i ask it here or do i need to open another thread?
treble/luna
treble/luna2mo ago
if the issue is related to djs, sure, you can ask here
jsw
jswOP2mo ago
Okay so i was trying to create a thread to the message, but i kept getting this error while trying to fetch it (sec i deleted the code so rewriting)
error: Uncaught (in promise) Error [ChannelNotCached]: Could not find the channel where this message came from in the cache!
at Message.startThread (file:///C:/Users/Jurn Wubben/AppData/Local/deno/npm/registry.npmjs.org/discord.js/14.16.3/src/structures/Message.js:951:46)
at createClashManager (file:///C:/Users/Jurn Wubben/Documents/DCBot/src/commands/utility/coc.ts:567:17)
at eventLoopTick (ext:core/01_core.js:175:7)
at async Object.execute (file:///C:/Users/Jurn Wubben/Documents/DCBot/src/commands/utility/coc.ts:618:5)
Watcher Process failed. Restarting on file change...
error: Uncaught (in promise) Error [ChannelNotCached]: Could not find the channel where this message came from in the cache!
at Message.startThread (file:///C:/Users/Jurn Wubben/AppData/Local/deno/npm/registry.npmjs.org/discord.js/14.16.3/src/structures/Message.js:951:46)
at createClashManager (file:///C:/Users/Jurn Wubben/Documents/DCBot/src/commands/utility/coc.ts:567:17)
at eventLoopTick (ext:core/01_core.js:175:7)
at async Object.execute (file:///C:/Users/Jurn Wubben/Documents/DCBot/src/commands/utility/coc.ts:618:5)
Watcher Process failed. Restarting on file change...
same code as the gist except i changed this part (line 556-570) (added fetchReply and startThread
const message = await interaction.reply({
...clashMessage({
handle: clash,
langs,
modes,
players: [{ nickname: "loading..." }],
started: false,
}, interaction.user.id),
fetchReply: true,
});

await message.startThread({
name: "Clash of Code",
reason: "Discuss your coc here.",
});
const message = await interaction.reply({
...clashMessage({
handle: clash,
langs,
modes,
players: [{ nickname: "loading..." }],
started: false,
}, interaction.user.id),
fetchReply: true,
});

await message.startThread({
name: "Clash of Code",
reason: "Discuss your coc here.",
});
do i need to fetch the channel before fetching the reply?
treble/luna
treble/luna2mo ago
do you have the Guilds intent? and did this happen in a guild?
jsw
jswOP2mo ago
it happened in a guild (i beleive you can't make threads in dms right?) and i do have the guild intent
export const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
],
});
export const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
],
});
treble/luna
treble/luna2mo ago
can you log message? and perhaps message.channel too also, did you invite your app with the bot scope
jsw
jswOP2mo ago
jsw
jswOP2mo ago
Oh that might be it it's running as a user app https://gist.github.com/jsw08/a006fbcd88f92b36a1203ca9d708880b
treble/luna
treble/luna2mo ago
yeah, a user app cannot create threads
jsw
jswOP2mo ago
oh that sucks. Thanks!

Did you find this page helpful?