-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (34 loc) · 1.67 KB
/
index.js
File metadata and controls
39 lines (34 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
*+--------------------------------------------------------------+
*| |
*| Strangely, when the same build is imported and used like |
*| `import Client from "./discord.http/index.js"`, it works |
*| perfectly. However, when the build is published to npm and |
*| used as `import Client from "discord.http"`, some functions |
*| don’t seem to get invoked, especially `__internal_dispatch` |
*| which is responsible for invoking the middlewares. I haven’t |
*| really used Cloudflare worker, but it works fine with |
*| Nodejs runtime. The only issue seems to be with Cloudflare’s |
*| V8 isolate runtime. |
*| |
*+--------------------------------------------------------------+
*/
// will look into it later.
import Client from "./discord.https/dist/index.js";
import CloudflareAdapter from "@discordhttps/cloudflare-adapter";
import UtilityRoute from "./command/utility/index.js";
import HelloRoute from "./command/fun/hello.js";
const adapter = new CloudflareAdapter();
export default {
async fetch(request, env, ctx) {
const client = new Client({
token: env.TOKEN, // npx wrangler secret put TOKEN
publicKey: env.PUBLICKEY, //npx wrangler secret put PUBLICKEY
httpAdapter: adapter,
});
// You can also directly use client.<interaction> without InteractionRouter,
// but using InteractionRouter is encouraged to keep the code cleaner and more modular.
client.register(UtilityRoute, HelloRoute);
return await client.listen("interactions", request);
},
};