create-discord-https 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/index.js +389 -0
- package/package.json +35 -0
- package/templates/cloudflare/README.md +32 -0
- package/templates/cloudflare/_gitignore +3 -0
- package/templates/cloudflare/package.json +26 -0
- package/templates/cloudflare/src/DevLayer.js +139 -0
- package/templates/cloudflare/src/commands/fun/joke.js +118 -0
- package/templates/cloudflare/src/commands/reply/ping.js +12 -0
- package/templates/cloudflare/src/commands/utility/help.js +73 -0
- package/templates/cloudflare/src/commands/utility/info.js +60 -0
- package/templates/cloudflare/src/commands/utility/profile.js +36 -0
- package/templates/cloudflare/src/spawner.js +17 -0
- package/templates/cloudflare/wrangler.jsonc +16 -0
- package/templates/cloudflare-ts/README.md +33 -0
- package/templates/cloudflare-ts/_gitignore +3 -0
- package/templates/cloudflare-ts/package.json +27 -0
- package/templates/cloudflare-ts/src/DevLayer.ts +140 -0
- package/templates/cloudflare-ts/src/commands/fun/joke.ts +125 -0
- package/templates/cloudflare-ts/src/commands/index.ts +14 -0
- package/templates/cloudflare-ts/src/commands/reply/ping.ts +12 -0
- package/templates/cloudflare-ts/src/commands/utility/help.ts +73 -0
- package/templates/cloudflare-ts/src/commands/utility/index.ts +14 -0
- package/templates/cloudflare-ts/src/commands/utility/info.ts +56 -0
- package/templates/cloudflare-ts/src/commands/utility/profile.ts +35 -0
- package/templates/cloudflare-ts/src/index.ts +60 -0
- package/templates/cloudflare-ts/src/spawner.js +17 -0
- package/templates/cloudflare-ts/tsconfig.json +18 -0
- package/templates/cloudflare-ts/wrangler.jsonc +19 -0
- package/templates/node/README.md +13 -0
- package/templates/node/_gitignore +3 -0
- package/templates/node/package.json +22 -0
- package/templates/node/src/DevLayer.js +135 -0
- package/templates/node/src/commands/fun/joke.js +118 -0
- package/templates/node/src/commands/reply/ping.js +12 -0
- package/templates/node/src/commands/utility/help.js +73 -0
- package/templates/node/src/commands/utility/info.js +60 -0
- package/templates/node/src/commands/utility/profile.js +36 -0
- package/templates/node-ts/README.md +10 -0
- package/templates/node-ts/_gitignore +3 -0
- package/templates/node-ts/package.json +24 -0
- package/templates/node-ts/src/DevLayer.ts +135 -0
- package/templates/node-ts/src/commands/fun/joke.ts +125 -0
- package/templates/node-ts/src/commands/index.ts +14 -0
- package/templates/node-ts/src/commands/reply/ping.ts +12 -0
- package/templates/node-ts/src/commands/utility/help.ts +73 -0
- package/templates/node-ts/src/commands/utility/index.ts +14 -0
- package/templates/node-ts/src/commands/utility/info.ts +56 -0
- package/templates/node-ts/src/commands/utility/profile.ts +35 -0
- package/templates/node-ts/src/index.ts +50 -0
- package/templates/vercel/.vercelignore +4 -0
- package/templates/vercel/README.md +30 -0
- package/templates/vercel/_gitignore +4 -0
- package/templates/vercel/api/interactions.js +5 -0
- package/templates/vercel/index.html +235 -0
- package/templates/vercel/package.json +23 -0
- package/templates/vercel/src/DevLayer.js +135 -0
- package/templates/vercel/src/commands/fun/joke.js +118 -0
- package/templates/vercel/src/commands/reply/ping.js +12 -0
- package/templates/vercel/src/commands/utility/help.js +73 -0
- package/templates/vercel/src/commands/utility/info.js +60 -0
- package/templates/vercel/src/commands/utility/profile.js +36 -0
- package/templates/vercel/src/spawner.js +18 -0
- package/templates/vercel-ts/.vercelignore +4 -0
- package/templates/vercel-ts/README.md +32 -0
- package/templates/vercel-ts/_gitignore +4 -0
- package/templates/vercel-ts/api/interactions.js +5 -0
- package/templates/vercel-ts/index.html +235 -0
- package/templates/vercel-ts/package.json +25 -0
- package/templates/vercel-ts/src/DevLayer.ts +135 -0
- package/templates/vercel-ts/src/commands/fun/joke.ts +125 -0
- package/templates/vercel-ts/src/commands/index.ts +14 -0
- package/templates/vercel-ts/src/commands/reply/ping.ts +12 -0
- package/templates/vercel-ts/src/commands/utility/help.ts +73 -0
- package/templates/vercel-ts/src/commands/utility/index.ts +14 -0
- package/templates/vercel-ts/src/commands/utility/info.ts +56 -0
- package/templates/vercel-ts/src/commands/utility/profile.ts +35 -0
- package/templates/vercel-ts/src/index.ts +48 -0
- package/templates/vercel-ts/src/spawner.js +18 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { InteractionRouterCollector } from "discord.https/router";
|
|
2
|
+
|
|
3
|
+
// Recommend using PascalCase and ending with the 'Route' suffix
|
|
4
|
+
// for variable naming convention
|
|
5
|
+
|
|
6
|
+
import JokeRoute from "./fun/joke.js";
|
|
7
|
+
import PingRoute from "./reply/ping.js";
|
|
8
|
+
import UtilityRoute from "./utility/index.js";
|
|
9
|
+
|
|
10
|
+
export default new InteractionRouterCollector().register(
|
|
11
|
+
JokeRoute,
|
|
12
|
+
PingRoute,
|
|
13
|
+
UtilityRoute
|
|
14
|
+
);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// https://discordhttps.js.org/classes/interactionRouter.InteractionRouter.html
|
|
2
|
+
import { InteractionRouter } from "discord.https/router";
|
|
3
|
+
|
|
4
|
+
const router = new InteractionRouter();
|
|
5
|
+
|
|
6
|
+
// https://discordhttps.js.org/classes/interactionRouter.InteractionRouter.html#command
|
|
7
|
+
router.command(
|
|
8
|
+
(builder) => builder.setName("ping").setDescription("says pong!"),
|
|
9
|
+
async (interaction) => await interaction.reply("Pong! 🏓")
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export default router;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MessageFlags,
|
|
3
|
+
MediaGalleryBuilder,
|
|
4
|
+
MediaGalleryItemBuilder,
|
|
5
|
+
TextDisplayBuilder,
|
|
6
|
+
SeparatorBuilder,
|
|
7
|
+
SeparatorSpacingSize,
|
|
8
|
+
ButtonBuilder,
|
|
9
|
+
ButtonStyle,
|
|
10
|
+
ActionRowBuilder,
|
|
11
|
+
} from "discord.https";
|
|
12
|
+
|
|
13
|
+
// https://discordhttps.js.org/classes/interactionRouter.InteractionRouter.html
|
|
14
|
+
import { InteractionRouter } from "discord.https/router";
|
|
15
|
+
|
|
16
|
+
const router = new InteractionRouter();
|
|
17
|
+
|
|
18
|
+
// https://discord.com/developers/docs/change-log/2025-04-22-components-v2
|
|
19
|
+
const components = [
|
|
20
|
+
new MediaGalleryBuilder().addItems(
|
|
21
|
+
new MediaGalleryItemBuilder().setURL(
|
|
22
|
+
"https://raw.githubusercontent.com/discordhttps/discord.https/refs/heads/main/assets/logo.png"
|
|
23
|
+
)
|
|
24
|
+
),
|
|
25
|
+
new TextDisplayBuilder().setContent(
|
|
26
|
+
"**Discord.https** is a robust, modular library for implementing Discord HTTP interactions."
|
|
27
|
+
),
|
|
28
|
+
new SeparatorBuilder()
|
|
29
|
+
.setSpacing(SeparatorSpacingSize.Large)
|
|
30
|
+
.setDivider(true),
|
|
31
|
+
new TextDisplayBuilder().setContent(
|
|
32
|
+
"## Commands Available in This Template\n- /help\n- /index\n- /info\n- Context User Command: Profile (right-click a user and select Apps > Profile)"
|
|
33
|
+
),
|
|
34
|
+
new TextDisplayBuilder().setContent("Related Links"),
|
|
35
|
+
new ActionRowBuilder().addComponents(
|
|
36
|
+
new ButtonBuilder()
|
|
37
|
+
.setStyle(ButtonStyle.Link)
|
|
38
|
+
.setLabel("Github")
|
|
39
|
+
.setEmoji({
|
|
40
|
+
name: "⭐",
|
|
41
|
+
})
|
|
42
|
+
.setURL("https://google.com"),
|
|
43
|
+
new ButtonBuilder()
|
|
44
|
+
.setStyle(ButtonStyle.Link)
|
|
45
|
+
.setLabel("Node Package")
|
|
46
|
+
.setEmoji({
|
|
47
|
+
name: "📦",
|
|
48
|
+
})
|
|
49
|
+
.setURL("https://www.npmjs.com/package/discord.https"),
|
|
50
|
+
new ButtonBuilder()
|
|
51
|
+
.setStyle(ButtonStyle.Link)
|
|
52
|
+
.setLabel("Documentation")
|
|
53
|
+
.setEmoji({
|
|
54
|
+
name: "📘",
|
|
55
|
+
})
|
|
56
|
+
.setURL("https://discordhttps.js.org/")
|
|
57
|
+
),
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
// https://discordhttps.js.org/classes/interactionRouter.InteractionRouter.html#command
|
|
61
|
+
router.command(
|
|
62
|
+
(builder) =>
|
|
63
|
+
builder
|
|
64
|
+
.setName("help")
|
|
65
|
+
.setDescription("Gives you information about discord.https"),
|
|
66
|
+
async (interaction) =>
|
|
67
|
+
await interaction.reply({
|
|
68
|
+
flags: MessageFlags.IsComponentsV2,
|
|
69
|
+
components: components,
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
export default router;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { InteractionRouterCollector } from "discord.https/router";
|
|
2
|
+
|
|
3
|
+
// Recommend using PascalCase and ending with the 'Route' suffix
|
|
4
|
+
// for variable naming convention
|
|
5
|
+
|
|
6
|
+
import HelpRoute from "./help.js";
|
|
7
|
+
import InfoRoute from "./info.js";
|
|
8
|
+
import ProfileRoute from "./profile.js";
|
|
9
|
+
|
|
10
|
+
export default new InteractionRouterCollector().register(
|
|
11
|
+
HelpRoute,
|
|
12
|
+
InfoRoute,
|
|
13
|
+
ProfileRoute
|
|
14
|
+
);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MessageFlags,
|
|
3
|
+
TextDisplayBuilder,
|
|
4
|
+
ButtonBuilder,
|
|
5
|
+
ButtonStyle,
|
|
6
|
+
ActionRowBuilder,
|
|
7
|
+
} from "discord.https";
|
|
8
|
+
|
|
9
|
+
// https://discordhttps.js.org/classes/interactionRouter.InteractionRouter.html
|
|
10
|
+
import { InteractionRouter } from "discord.https/router";
|
|
11
|
+
|
|
12
|
+
const router = new InteractionRouter();
|
|
13
|
+
|
|
14
|
+
// https://discord.com/developers/docs/change-log/2025-04-22-components-v2
|
|
15
|
+
const components = [
|
|
16
|
+
new TextDisplayBuilder().setContent("Served via `src/utility/info.js`"),
|
|
17
|
+
new TextDisplayBuilder().setContent("Related Links"),
|
|
18
|
+
new ActionRowBuilder().addComponents(
|
|
19
|
+
new ButtonBuilder()
|
|
20
|
+
.setStyle(ButtonStyle.Link)
|
|
21
|
+
.setLabel("Github")
|
|
22
|
+
.setEmoji({
|
|
23
|
+
name: "⭐",
|
|
24
|
+
})
|
|
25
|
+
.setURL("https://google.com"),
|
|
26
|
+
new ButtonBuilder()
|
|
27
|
+
.setStyle(ButtonStyle.Link)
|
|
28
|
+
.setLabel("Node Package")
|
|
29
|
+
.setEmoji({
|
|
30
|
+
name: "📦",
|
|
31
|
+
})
|
|
32
|
+
.setURL("https://www.npmjs.com/package/discord.https"),
|
|
33
|
+
new ButtonBuilder()
|
|
34
|
+
.setStyle(ButtonStyle.Link)
|
|
35
|
+
.setLabel("Documentation")
|
|
36
|
+
.setEmoji({
|
|
37
|
+
name: "📘",
|
|
38
|
+
})
|
|
39
|
+
.setURL("https://discordhttps.js.org/")
|
|
40
|
+
),
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
// https://discordhttps.js.org/classes/interactionRouter.InteractionRouter.html#command
|
|
44
|
+
router.command(
|
|
45
|
+
(builder) =>
|
|
46
|
+
builder
|
|
47
|
+
.setName("info")
|
|
48
|
+
.setDescription("Gives you information about discord.https"),
|
|
49
|
+
async (interaction) =>
|
|
50
|
+
await interaction.reply({
|
|
51
|
+
flags: MessageFlags.IsComponentsV2,
|
|
52
|
+
components: components,
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
export default router;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// https://discordhttps.js.org/classes/interactionRouter.InteractionRouter.html
|
|
2
|
+
import { InteractionRouter } from "discord.https/router";
|
|
3
|
+
|
|
4
|
+
const router = new InteractionRouter();
|
|
5
|
+
|
|
6
|
+
// https://discordhttps.js.org/classes/interactionRouter.InteractionRouter.html#usercontextmenu
|
|
7
|
+
|
|
8
|
+
// https://discord.com/developers/docs/reference#image-formatting
|
|
9
|
+
|
|
10
|
+
router.userContextMenu(
|
|
11
|
+
(builder) => builder.setName("profile"),
|
|
12
|
+
async (interaction) => {
|
|
13
|
+
const user = interaction.targetUser;
|
|
14
|
+
|
|
15
|
+
// In the case of endpoints that support GIFs, the hash will begin with a_ if it is available in GIF format.
|
|
16
|
+
const avatarFormat =
|
|
17
|
+
user.avatar && user.avatar!.startsWith("a_") ? "gif" : "png";
|
|
18
|
+
|
|
19
|
+
const avatarUrl = user.avatar
|
|
20
|
+
? `/avatars/${user.id}/${user.avatar}.${avatarFormat}`
|
|
21
|
+
: // In the case of the Default User Avatar endpoint, the value for index depends on whether the user is migrated to the new username system.
|
|
22
|
+
// For users on the new username system, index will be (user_id >> 22) % 6.
|
|
23
|
+
// For users on the legacy username system, index will be discriminator % 5.
|
|
24
|
+
`/embed/avatars/${
|
|
25
|
+
Number(user.discriminator)
|
|
26
|
+
? Number(user.discriminator) % 5
|
|
27
|
+
: (BigInt(user.id) >> 22n) % 6n
|
|
28
|
+
}.png`;
|
|
29
|
+
|
|
30
|
+
// https://discord.com/developers/docs/reference#image-formatting
|
|
31
|
+
await interaction.reply(`https://cdn.discordapp.com/${avatarUrl}`);
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
export default router;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import Client from "discord.https";
|
|
2
|
+
import VercelAdapter from "@discordhttps/vercel-adapter";
|
|
3
|
+
|
|
4
|
+
import commands from "./commands/index.js";
|
|
5
|
+
|
|
6
|
+
const adapter = new VercelAdapter();
|
|
7
|
+
|
|
8
|
+
const client = new Client({
|
|
9
|
+
token: "PUT_YOUR_TOKEN_HERE",
|
|
10
|
+
publicKey: "PUT_YOUR_PUBLIC_KEY_HERE",
|
|
11
|
+
httpAdapter: adapter,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// client.middleware() creates a global middleware, which is always executed before
|
|
15
|
+
// route middleware/handlers.
|
|
16
|
+
|
|
17
|
+
// https://discordhttps.js.org/classes/index.default.html#middleware
|
|
18
|
+
client.middleware(async (interaction) => {
|
|
19
|
+
const username = interaction.inGuild()
|
|
20
|
+
? interaction.member.user.username
|
|
21
|
+
: interaction.user.username;
|
|
22
|
+
console.log("[Global Middleware]: A command has been invoked by: ", username);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Everything here is middleware. A middleware can be defined as a function that takes a parameter
|
|
26
|
+
// and transforms the output in our case.
|
|
27
|
+
|
|
28
|
+
// client.register() mounts a middleware. This means that if the client receives a request from Discord
|
|
29
|
+
// and the corresponding middleware exists, the client will pass it to the appropriate middleware
|
|
30
|
+
// one by one in the order they were registered.
|
|
31
|
+
|
|
32
|
+
// simply, .register() lets the client know that these are the handlers.
|
|
33
|
+
client.register(commands);
|
|
34
|
+
|
|
35
|
+
if (process.env.NODE_ENV !== "production") {
|
|
36
|
+
const { commandRegistrarLayer } = await import("./DevLayer.js");
|
|
37
|
+
|
|
38
|
+
// if (!(globalThis as any).__TUNNEL_LAYER__)
|
|
39
|
+
// (globalThis as any).__TUNNEL_LAYER__ = await tunnelLayer();
|
|
40
|
+
|
|
41
|
+
// automatic command registration to discord.
|
|
42
|
+
// The second parameter is the guild ID. If a guild ID is provided, the command will be registered for that guild; otherwise, it will be registered globally.
|
|
43
|
+
await commandRegistrarLayer(client, undefined);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Only api/<file.js/ts> can be serverless function, exporting it for api/interaction
|
|
47
|
+
// so, it cloud be imported from api/interaction.js and use there due to vercel way of serverless
|
|
48
|
+
export default client;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// ------------It is recommended not to modify this spawner code------------
|
|
2
|
+
|
|
3
|
+
import { spawn } from "child_process";
|
|
4
|
+
import chalk from "chalk"; // npm install chalk
|
|
5
|
+
|
|
6
|
+
import { tunnelLayer } from "./DevLayer";
|
|
7
|
+
|
|
8
|
+
await tunnelLayer();
|
|
9
|
+
console.log(chalk.greenBright("Tunnel spawned and ready!\n\n"));
|
|
10
|
+
|
|
11
|
+
const vercel = spawn("vercel", ["dev"], {
|
|
12
|
+
stdio: "inherit", // we’ll handle colors ourselves
|
|
13
|
+
});
|
|
14
|
+
3;
|
|
15
|
+
|
|
16
|
+
vercel.on("close", (code) => {
|
|
17
|
+
console.log(chalk.yellow(`Vercel dev exited with code ${code}`));
|
|
18
|
+
});
|