Execute something after return
I want to use Workers AI on Discord through my bot, AI content takes a long time to generate, so I need to respond Discord first and update the result later.
Is there a way to solve it?
By the way, how do I get my account ID?
9 Replies
Hi
Let me answer your second question first, your account id can be found in multiple locations:
go to workers & pages in the dashboard, and find it on the right hand side in a click-to-copy box. It is also in the url, a long hexadecimal string
As for the first one, workers have a special way to achieve this: https://developers.cloudflare.com/workers/runtime-apis/handlers/fetch/#contextwaituntil
In that waitUntil, put your promise that resolves after the initial response, so your code looks something like this:
Thanks for your help, I copied example from Discord documentation, it doesn’t have the
context
argument. How can I use it?
hmm, what router is that example using?
Here is the example:
https://github.com/discord/cloudflare-sample-app/blob/main/src/server.js
GitHub
cloudflare-sample-app/src/server.js at main · discord/cloudflare-sa...
Example discord bot using Cloudflare Workers. Contribute to discord/cloudflare-sample-app development by creating an account on GitHub.
Just add a third param, after env
async (request, env, ctx) => {
https://github.com/kwhitley/itty-router#4-only-one-required-argument--the-rest-is-up-to-youitty-router it is haha
I tried but failed
Modify the
server
object at the bottom as well to include them, like thisIt works! Thank you so much!