create-discord-bot 0.0.6 → 0.2.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.
Files changed (31) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE +190 -0
  3. package/README.md +43 -2
  4. package/dist/index.mjs +4 -0
  5. package/package.json +67 -5
  6. package/template/JavaScript/.env +2 -0
  7. package/template/JavaScript/.eslintrc.json +9 -0
  8. package/template/JavaScript/.prettierrc.json +8 -0
  9. package/template/JavaScript/package.json +23 -0
  10. package/template/JavaScript/src/commands/index.js +21 -0
  11. package/template/JavaScript/src/commands/ping.js +10 -0
  12. package/template/JavaScript/src/events/index.js +23 -0
  13. package/template/JavaScript/src/events/ready.js +10 -0
  14. package/template/JavaScript/src/index.js +17 -0
  15. package/template/JavaScript/src/util/deploy.js +15 -0
  16. package/template/JavaScript/src/util/loaders.js +83 -0
  17. package/template/JavaScript/src/util/registerEvents.js +29 -0
  18. package/template/TypeScript/.env +2 -0
  19. package/template/TypeScript/.eslintrc.json +8 -0
  20. package/template/TypeScript/.prettierrc.json +8 -0
  21. package/template/TypeScript/package.json +27 -0
  22. package/template/TypeScript/src/commands/index.ts +27 -0
  23. package/template/TypeScript/src/commands/ping.ts +11 -0
  24. package/template/TypeScript/src/events/index.ts +33 -0
  25. package/template/TypeScript/src/events/ready.ts +10 -0
  26. package/template/TypeScript/src/index.ts +17 -0
  27. package/template/TypeScript/src/util/deploy.ts +15 -0
  28. package/template/TypeScript/src/util/loaders.ts +76 -0
  29. package/template/TypeScript/src/util/registerEvents.ts +25 -0
  30. package/template/TypeScript/tsconfig.eslint.json +8 -0
  31. package/template/TypeScript/tsconfig.json +11 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ # [create-discord-bot/0.2.0](https://github.com/discordjs/discord.js/compare/create-discord-bot@0.1.0...create-discord-bot@0.2.0) - (2023-07-31)
6
+
7
+ ## Bug Fixes
8
+
9
+ - Resolve imports for Windows (#9546) ([b6162bc](https://github.com/discordjs/discord.js/commit/b6162bc5b582089a9405d29f6825d9748180f66a))
10
+ - Non-existing data property (#9544) ([5b8d535](https://github.com/discordjs/discord.js/commit/5b8d535fd633ff25dd801f35e13b4cb169cc42ac))
11
+ - **create-discord-bot:** Fix start script (#9542) ([8482e3c](https://github.com/discordjs/discord.js/commit/8482e3c95dd5ca086805e756afdcf787e3fea1f9))
12
+
13
+ ## Documentation
14
+
15
+ - Add Cloudflare sponsorship in `create-discord-bot` readme (#9540) ([12482b7](https://github.com/discordjs/discord.js/commit/12482b70ed4bfadf26720f9b2ed9d7bf7ccc39b8))
16
+
17
+ ## Features
18
+
19
+ - **create-discord-bot:** Throw error if the directory is a file (#9719) ([351a18b](https://github.com/discordjs/discord.js/commit/351a18bc35da7765d281e419b646ef734a315bdf))
20
+ - **create-discord-bot:** Add prompts, command handler and deployment script (#9570) ([84f1b18](https://github.com/discordjs/discord.js/commit/84f1b1890de5add805bef1a030b0ade3c6aca213))
21
+ - Check for empty directory (#9539) ([64324a8](https://github.com/discordjs/discord.js/commit/64324a8be13dc2b766636a1042ae13d3d52a5c79))
22
+ - **create-discord-bot:** Inherit stdio when installing deps (#9543) ([c4a3120](https://github.com/discordjs/discord.js/commit/c4a3120354ea3930e010ba011216e42311e29cdb))
23
+
24
+ # [0.1.0](https://github.com/discordjs/discord.js/tree/0.1.0) - (2023-05-07)
25
+
26
+ ## Features
27
+
28
+ - Create-discord-bot (#9420) ([f83a8a5](https://github.com/discordjs/discord.js/commit/f83a8a58c99532131848f9d89cec58ae5cd5d138))
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2023 Noel Buechler
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,44 @@
1
- # create-discord-bot
1
+ <div align="center">
2
+ <br />
3
+ <p>
4
+ <a href="https://discord.js.org"><img src="https://discord.js.org/static/logo.svg" width="546" alt="discord.js" /></a>
5
+ </p>
6
+ <br />
7
+ <p>
8
+ <a href="https://discord.gg/djs"><img src="https://img.shields.io/discord/222078108977594368?color=5865F2&logo=discord&logoColor=white" alt="Discord server" /></a>
9
+ <a href="https://github.com/discordjs/discord.js/actions"><img src="https://github.com/discordjs/discord.js/actions/workflows/test.yml/badge.svg" alt="Build status" /></a>
10
+ </p>
11
+ <p>
12
+ <a href="https://vercel.com/?utm_source=discordjs&utm_campaign=oss"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-vercel.svg" alt="Vercel" /></a>
13
+ <a href="https://www.cloudflare.com"><img src="https://raw.githubusercontent.com/discordjs/discord.js/main/.github/powered-by-workers.png" alt="Cloudflare Workers" height="44" /></a>
14
+ </p>
15
+ </div>
2
16
 
3
- A work-in-progress startup utility to initialise a Discord bot.
17
+ ## About
18
+
19
+ `npx create-discord-bot ./your/chosen/directory/`. It's as easy as that to create a simple Discord bot to begin your journey with the Discord API.
20
+
21
+ ## Links
22
+
23
+ - [Guide] ([source][guide-source])
24
+ - Also see the v13 to v14 [Update Guide][guide-update], which includes updated and removed items from the library.
25
+ - [discord.js Discord server][discord]
26
+ - [Discord API Discord server][discord-api]
27
+ - [GitHub][source]
28
+
29
+ ## Contributing
30
+
31
+ Before creating an issue, please ensure that it hasn't already been reported/suggested.
32
+ See [the contribution guide][contributing] if you'd like to submit a pull request.
33
+
34
+ ## Help
35
+
36
+ If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official [discord.js server][discord].
37
+
38
+ [guide]: https://discordjs.guide/
39
+ [guide-source]: https://github.com/discordjs/guide
40
+ [guide-update]: https://discordjs.guide/additional-info/changes-in-v14.html
41
+ [discord]: https://discord.gg/djs
42
+ [discord-api]: https://discord.gg/discord-api
43
+ [source]: https://github.com/discordjs/discord.js/tree/main/packages/create-discord-bot
44
+ [contributing]: https://github.com/discordjs/discord.js/blob/main/.github/CONTRIBUTING.md
package/dist/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ var b=Object.defineProperty;var n=(e,o)=>b(e,"name",{value:o,configurable:!0});import{program as A}from"commander";import E from"prompts";import{cp as T,stat as v,mkdir as D,readdir as _,readFile as C,writeFile as U}from"node:fs/promises";import j from"node:path";import c from"node:process";import{URL as L}from"node:url";import r from"chalk";import R from"validate-npm-package-name";import{execSync as x}from"node:child_process";import N from"node:process";import S from"chalk";var s="npm",u="https://guide.discordjs.dev";function h(){let e=N.env.npm_config_user_agent;return e?e.startsWith("npm")?"npm":e.startsWith("yarn")?"yarn":e.startsWith("pnpm")?"pnpm":(console.error(S.yellow(`Detected an unsupported package manager (${e}). Falling back to ${s}.`)),s):s}n(h,"resolvePackageManager");function w(e){let o;switch(e){case"npm":case"pnpm":o=`${e} install`;break;case"yarn":o=e;break}console.log(`Installing dependencies with ${e}...`),x(o,{stdio:"inherit"})}n(w,"install");async function k({typescript:e,javascript:o,directory:g}){g||(console.error(r.red("Please specify the project directory.")),c.exit(1));let t=j.resolve(g),a=j.basename(t);(!(await v(t).catch(async i=>{if(i.code==="ENOENT")return await D(t,{recursive:!0}),v(t);throw i})).isDirectory()||(await _(t)).length>0)&&(console.error(r.red(`The directory ${r.yellow(`"${a}"`)} is either not a directory or is not empty.`)),console.error(r.red("Please specify an empty directory.")),c.exit(1));let p=R(a);if(!p.validForNewPackages){console.error(r.red(`Cannot create a project named ${r.yellow(`"${a}"`)} due to npm naming restrictions.
2
+
3
+ Errors:`));for(let i of[...p.errors??[],...p.warnings??[]])console.error(r.red(`- ${i}`));console.error(r.red(`
4
+ See https://docs.npmjs.com/cli/configuring-npm/package-json for more details.`)),c.exit(1)}console.log(`Creating ${a} in ${r.green(t)}.`),await T(new L(`../template/${e?"TypeScript":"JavaScript"}`,import.meta.url),t,{recursive:!0}),c.chdir(t);let P=await C("./package.json",{encoding:"utf8"}).then(i=>i.replace("[REPLACE-NAME]",a));await U("./package.json",P);let $=h();w($),console.log(r.green("All done! Be sure to read through the discord.js guide for help on your journey.")),console.log(`Link: ${r.cyan(u)}`)}n(k,"createDiscordBot");A.description("Create a basic discord.js bot.").option("--directory","The directory where this will be created.").option("--typescript","Whether to use the TypeScript template.").option("--javascript","Whether to use the JavaScript template.").parse();var{typescript:d,javascript:y,directory:f}=A.opts();f||(f=(await E({type:"text",name:"directory",initial:"my-bot",message:"What is the name of the directory you want to create this project in?"})).directory);if(d===void 0&&y===void 0){let{useTypescript:e}=await E({type:"toggle",name:"useTypescript",message:"Do you want to use TypeScript?",initial:!0,active:"Yes",inactive:"No"});d=e,y=!e}await k({typescript:d,javascript:y,directory:f});
package/package.json CHANGED
@@ -1,13 +1,75 @@
1
1
  {
2
2
  "name": "create-discord-bot",
3
- "version": "0.0.6",
3
+ "version": "0.2.0",
4
+ "description": "A simple way to create a startup Discord bot.",
5
+ "scripts": {
6
+ "build": "tsup",
7
+ "lint": "prettier --check . && cross-env TIMING=1 eslint src --ext .mjs,.js,.ts --format=pretty",
8
+ "format": "prettier --write . && cross-env TIMING=1 eslint src --ext .mjs,.js,.ts --fix --format=pretty",
9
+ "prepack": "yarn build && yarn lint",
10
+ "changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/create-discord-bot/*'",
11
+ "release": "cliff-jumper"
12
+ },
13
+ "bin": "./dist/index.mjs",
14
+ "directories": {
15
+ "lib": "src"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "template"
20
+ ],
21
+ "contributors": [
22
+ "Crawl <icrawltogo@gmail.com>",
23
+ "SpaceEEC <spaceeec@yahoo.com>",
24
+ "Vlad Frangu <kingdgrizzle@gmail.com>",
25
+ "Aura Román <kyradiscord@gmail.com>",
26
+ "Jiralite <jiralite@live.co.uk>"
27
+ ],
28
+ "license": "Apache-2.0",
29
+ "keywords": [
30
+ "discord",
31
+ "discord-api",
32
+ "discord.js",
33
+ "create-bot",
34
+ "init-bot",
35
+ "init-discord",
36
+ "boilerplate"
37
+ ],
4
38
  "repository": {
5
39
  "type": "git",
6
- "url": "https://github.com/discordjs/discord.js"
40
+ "url": "git+https://github.com/discordjs/discord.js.git",
41
+ "directory": "packages/create-discord-bot"
7
42
  },
8
43
  "bugs": {
9
44
  "url": "https://github.com/discordjs/discord.js/issues"
10
45
  },
11
- "description": "A startup utility for creating a Discord bot.",
12
- "author": "Jiralite"
13
- }
46
+ "homepage": "https://discord.js.org",
47
+ "dependencies": {
48
+ "chalk": "^5.3.0",
49
+ "commander": "^11.0.0",
50
+ "prompts": "^2.4.2",
51
+ "validate-npm-package-name": "^5.0.0"
52
+ },
53
+ "devDependencies": {
54
+ "@favware/cliff-jumper": "^2.1.1",
55
+ "@microsoft/api-extractor": "^7.36.3",
56
+ "@types/node": "16.18.39",
57
+ "@types/prompts": "^2.4.4",
58
+ "@types/validate-npm-package-name": "^4.0.0",
59
+ "@vitest/coverage-c8": "^0.33.0",
60
+ "cross-env": "^7.0.3",
61
+ "eslint": "^8.46.0",
62
+ "eslint-config-neon": "^0.1.47",
63
+ "eslint-formatter-pretty": "^5.0.0",
64
+ "prettier": "^2.8.8",
65
+ "tsup": "^7.1.0",
66
+ "typescript": "^5.1.6",
67
+ "vitest": "^0.33.0"
68
+ },
69
+ "engines": {
70
+ "node": ">=18.16.0"
71
+ },
72
+ "publishConfig": {
73
+ "access": "public"
74
+ }
75
+ }
@@ -0,0 +1,2 @@
1
+ DISCORD_TOKEN=
2
+ APPLICATION_ID=
@@ -0,0 +1,9 @@
1
+ {
2
+ "root": true,
3
+ "extends": ["neon/common", "neon/node", "neon/prettier"],
4
+ "rules": {
5
+ "jsdoc/valid-types": 0,
6
+ "jsdoc/check-tag-names": 0,
7
+ "jsdoc/no-undefined-types": 0
8
+ }
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "printWidth": 120,
3
+ "useTabs": true,
4
+ "singleQuote": true,
5
+ "quoteProps": "as-needed",
6
+ "trailingComma": "all",
7
+ "endOfLine": "lf"
8
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "[REPLACE-NAME]",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "lint": "prettier --check . && eslint src --ext .js,.cjs --format=pretty",
8
+ "format": "prettier --write . && eslint src --ext .js,.cjs --fix --format=pretty",
9
+ "start": "node --require dotenv/config src/index.js",
10
+ "deploy": "node --require dotenv/config src/util/deploy.js"
11
+ },
12
+ "dependencies": {
13
+ "@discordjs/core": "^0.6.0",
14
+ "discord.js": "^14.11.0",
15
+ "dotenv": "^16.0.3"
16
+ },
17
+ "devDependencies": {
18
+ "eslint": "^8.40.0",
19
+ "eslint-config-neon": "^0.1.47",
20
+ "eslint-formatter-pretty": "^5.0.0",
21
+ "prettier": "^2.8.8"
22
+ }
23
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Defines the structure of a command.
3
+ *
4
+ * @typedef {object} Command
5
+ * @property {import('discord.js').RESTPostAPIApplicationCommandsJSONBody} data The data for the command
6
+ * @property {(interaction: import('discord.js').CommandInteraction) => Promise<void> | void} execute The function to execute when the command is called
7
+ */
8
+
9
+ /**
10
+ * Defines the predicate to check if an object is a valid Command type.
11
+ *
12
+ * @type {import('../util/loaders.js').StructurePredicate<Command>}
13
+ * @returns {structure is Command}
14
+ */
15
+ export const predicate = (structure) =>
16
+ Boolean(structure) &&
17
+ typeof structure === 'object' &&
18
+ 'data' in structure &&
19
+ 'execute' in structure &&
20
+ typeof structure.data === 'object' &&
21
+ typeof structure.execute === 'function';
@@ -0,0 +1,10 @@
1
+ /** @type {import('./index.js').Command} */
2
+ export default {
3
+ data: {
4
+ name: 'ping',
5
+ description: 'Ping!',
6
+ },
7
+ async execute(interaction) {
8
+ await interaction.reply('Pong!');
9
+ },
10
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Defines the structure of an event.
3
+ *
4
+ * @template {keyof import('discord.js').ClientEvents} [T=keyof import('discord.js').ClientEvents]
5
+ * @typedef {object} Event
6
+ * @property {(...parameters: import('discord.js').ClientEvents[T]) => Promise<void> | void} execute The function to execute the command
7
+ * @property {T} name The name of the event to listen to
8
+ * @property {boolean} [once] Whether or not the event should only be listened to once
9
+ */
10
+
11
+ /**
12
+ * Defines the predicate to check if an object is a valid Event type.
13
+ *
14
+ * @type {import('../util/loaders').StructurePredicate<Event>}
15
+ * @returns {structure is Event}
16
+ */
17
+ export const predicate = (structure) =>
18
+ Boolean(structure) &&
19
+ typeof structure === 'object' &&
20
+ 'name' in structure &&
21
+ 'execute' in structure &&
22
+ typeof structure.name === 'string' &&
23
+ typeof structure.execute === 'function';
@@ -0,0 +1,10 @@
1
+ import { Events } from 'discord.js';
2
+
3
+ /** @type {import('./index.js').Event<Events.ClientReady>} */
4
+ export default {
5
+ name: Events.ClientReady,
6
+ once: true,
7
+ async execute(client) {
8
+ console.log(`Ready! Logged in as ${client.user.tag}`);
9
+ },
10
+ };
@@ -0,0 +1,17 @@
1
+ import { URL } from 'node:url';
2
+ import { Client, GatewayIntentBits } from 'discord.js';
3
+ import { loadCommands, loadEvents } from './util/loaders.js';
4
+ import { registerEvents } from './util/registerEvents.js';
5
+
6
+ // Initialize the client
7
+ const client = new Client({ intents: [GatewayIntentBits.Guilds] });
8
+
9
+ // Load the events and commands
10
+ const events = await loadEvents(new URL('events/', import.meta.url));
11
+ const commands = await loadCommands(new URL('commands/', import.meta.url));
12
+
13
+ // Register the event handlers
14
+ registerEvents(commands, events, client);
15
+
16
+ // Login to the client
17
+ void client.login();
@@ -0,0 +1,15 @@
1
+ import process from 'node:process';
2
+ import { URL } from 'node:url';
3
+ import { API } from '@discordjs/core/http-only';
4
+ import { REST } from 'discord.js';
5
+ import { loadCommands } from './loaders.js';
6
+
7
+ const commands = await loadCommands(new URL('commands/', import.meta.url));
8
+ const commandData = [...commands.values()].map((command) => command.data);
9
+
10
+ const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
11
+ const api = new API(rest);
12
+
13
+ const result = await api.applicationCommands.bulkOverwriteGlobalCommands(process.env.APPLICATION_ID, commandData);
14
+
15
+ console.log(`Successfully registered ${result.length} commands.`);
@@ -0,0 +1,83 @@
1
+ import { readdir, stat } from 'node:fs/promises';
2
+ import { URL } from 'node:url';
3
+ import { predicate as commandPredicate } from '../commands/index.js';
4
+ import { predicate as eventPredicate } from '../events/index.js';
5
+
6
+ /**
7
+ * A predicate to check if the structure is valid.
8
+ *
9
+ * @template T
10
+ * @typedef {(structure: unknown) => structure is T} StructurePredicate
11
+ */
12
+
13
+ /**
14
+ * Loads all the structures in the provided directory.
15
+ *
16
+ * @template T
17
+ * @param {import('node:fs').PathLike} dir - The directory to load the structures from
18
+ * @param {StructurePredicate<T>} predicate - The predicate to check if the structure is valid
19
+ * @param {boolean} recursive - Whether to recursively load the structures in the directory
20
+ * @returns {Promise<T[]>}
21
+ */
22
+ export async function loadStructures(dir, predicate, recursive = true) {
23
+ // Get the stats of the directory
24
+ const statDir = await stat(dir);
25
+
26
+ // If the provided directory path is not a directory, throw an error
27
+ if (!statDir.isDirectory()) {
28
+ throw new Error(`The directory '${dir}' is not a directory.`);
29
+ }
30
+
31
+ // Get all the files in the directory
32
+ const files = await readdir(dir);
33
+
34
+ // Create an empty array to store the structures
35
+ /** @type {T[]} */
36
+ const structures = [];
37
+
38
+ // Loop through all the files in the directory
39
+ for (const file of files) {
40
+ // If the file is index.js or the file does not end with .js, skip the file
41
+ if (file === 'index.js' || !file.endsWith('.js')) {
42
+ continue;
43
+ }
44
+
45
+ // Get the stats of the file
46
+ const statFile = await stat(new URL(`${dir}/${file}`));
47
+
48
+ // If the file is a directory and recursive is true, recursively load the structures in the directory
49
+ if (statFile.isDirectory() && recursive) {
50
+ structures.push(...(await loadStructures(`${dir}/${file}`, predicate, recursive)));
51
+ continue;
52
+ }
53
+
54
+ // Import the structure dynamically from the file
55
+ const structure = (await import(`${dir}/${file}`)).default;
56
+
57
+ // If the structure is a valid structure, add it
58
+ if (predicate(structure)) structures.push(structure);
59
+ }
60
+
61
+ return structures;
62
+ }
63
+
64
+ /**
65
+ * @param {import('node:fs').PathLike} dir
66
+ * @param {boolean} [recursive]
67
+ * @returns {Promise<Map<string,import('../commands/index.js').Command>>}
68
+ */
69
+ export async function loadCommands(dir, recursive = true) {
70
+ return (await loadStructures(dir, commandPredicate, recursive)).reduce(
71
+ (acc, cur) => acc.set(cur.data.name, cur),
72
+ new Map(),
73
+ );
74
+ }
75
+
76
+ /**
77
+ * @param {import('node:fs').PathLike} dir
78
+ * @param {boolean} [recursive]
79
+ * @returns {Promise<import('../events/index.js').Event[]>}
80
+ */
81
+ export async function loadEvents(dir, recursive = true) {
82
+ return loadStructures(dir, eventPredicate, recursive);
83
+ }
@@ -0,0 +1,29 @@
1
+ import { Events } from 'discord.js';
2
+
3
+ /**
4
+ * @param {Map<string, import('../commands/index.js').Command>} commands
5
+ * @param {import('../events/index.js').Event[]} events
6
+ * @param {import('discord.js').Client} client
7
+ */
8
+ export function registerEvents(commands, events, client) {
9
+ // Create an event to handle command interactions
10
+ /** @type {import('../events/index.js').Event<Events.InteractionCreate>} */
11
+ const interactionCreateEvent = {
12
+ name: Events.InteractionCreate,
13
+ async execute(interaction) {
14
+ if (interaction.isCommand()) {
15
+ const command = commands.get(interaction.commandName);
16
+
17
+ if (!command) {
18
+ throw new Error(`Command '${interaction.commandName}' not found.`);
19
+ }
20
+
21
+ await command.execute(interaction);
22
+ }
23
+ },
24
+ };
25
+
26
+ for (const event of [...events, interactionCreateEvent]) {
27
+ client[event.once ? 'once' : 'on'](event.name, async (...args) => event.execute(...args));
28
+ }
29
+ }
@@ -0,0 +1,2 @@
1
+ DISCORD_TOKEN=
2
+ APPLICATION_ID=
@@ -0,0 +1,8 @@
1
+ {
2
+ "root": true,
3
+ "extends": ["neon/common", "neon/node", "neon/typescript", "neon/prettier"],
4
+ "parserOptions": {
5
+ "project": ["./tsconfig.eslint.json"]
6
+ },
7
+ "ignorePatterns": ["dist/*"]
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "printWidth": 120,
3
+ "useTabs": true,
4
+ "singleQuote": true,
5
+ "quoteProps": "as-needed",
6
+ "trailingComma": "all",
7
+ "endOfLine": "lf"
8
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "[REPLACE-NAME]",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "test": "tsc",
8
+ "lint": "prettier --check . && eslint ./src --ext .ts --format=pretty",
9
+ "deploy": "node --require dotenv/config dist/util/deploy.js",
10
+ "format": "prettier --write . && eslint ./src --ext .ts --fix --format=pretty",
11
+ "start": "node --require dotenv/config dist/index.js"
12
+ },
13
+ "dependencies": {
14
+ "@discordjs/core": "^0.6.0",
15
+ "discord.js": "^14.11.0",
16
+ "dotenv": "^16.0.3"
17
+ },
18
+ "devDependencies": {
19
+ "@sapphire/ts-config": "^4.0.0",
20
+ "@types/node": "^18.15.3",
21
+ "eslint": "^8.40.0",
22
+ "eslint-config-neon": "^0.1.47",
23
+ "eslint-formatter-pretty": "^5.0.0",
24
+ "prettier": "^2.8.8",
25
+ "typescript": "^5.0.4"
26
+ }
27
+ }
@@ -0,0 +1,27 @@
1
+ import type { RESTPostAPIApplicationCommandsJSONBody, CommandInteraction } from 'discord.js';
2
+ import type { StructurePredicate } from '../util/loaders.js';
3
+
4
+ /**
5
+ * Defines the structure of a command
6
+ */
7
+ export type Command = {
8
+ /**
9
+ * The data for the command
10
+ */
11
+ data: RESTPostAPIApplicationCommandsJSONBody;
12
+ /**
13
+ * The function to execute when the command is called
14
+ *
15
+ * @param interaction - The interaction of the command
16
+ */
17
+ execute(interaction: CommandInteraction): Promise<void> | void;
18
+ };
19
+
20
+ // Defines the predicate to check if an object is a valid Command type
21
+ export const predicate: StructurePredicate<Command> = (structure): structure is Command =>
22
+ Boolean(structure) &&
23
+ typeof structure === 'object' &&
24
+ 'data' in structure! &&
25
+ 'execute' in structure &&
26
+ typeof structure.data === 'object' &&
27
+ typeof structure.execute === 'function';
@@ -0,0 +1,11 @@
1
+ import type { Command } from './index.js';
2
+
3
+ export default {
4
+ data: {
5
+ name: 'ping',
6
+ description: 'Ping!',
7
+ },
8
+ async execute(interaction) {
9
+ await interaction.reply('Pong!');
10
+ },
11
+ } satisfies Command;
@@ -0,0 +1,33 @@
1
+ import type { ClientEvents } from 'discord.js';
2
+ import type { StructurePredicate } from '../util/loaders.js';
3
+
4
+ /**
5
+ * Defines the structure of an event.
6
+ */
7
+ export type Event<T extends keyof ClientEvents = keyof ClientEvents> = {
8
+ /**
9
+ * The function to execute when the event is emitted.
10
+ *
11
+ * @param parameters - The parameters of the event
12
+ */
13
+ execute(...parameters: ClientEvents[T]): Promise<void> | void;
14
+ /**
15
+ * The name of the event to listen to
16
+ */
17
+ name: T;
18
+ /**
19
+ * Whether or not the event should only be listened to once
20
+ *
21
+ * @defaultValue false
22
+ */
23
+ once?: boolean;
24
+ };
25
+
26
+ // Defines the predicate to check if an object is a valid Event type.
27
+ export const predicate: StructurePredicate<Event> = (structure): structure is Event =>
28
+ Boolean(structure) &&
29
+ typeof structure === 'object' &&
30
+ 'name' in structure! &&
31
+ 'execute' in structure &&
32
+ typeof structure.name === 'string' &&
33
+ typeof structure.execute === 'function';
@@ -0,0 +1,10 @@
1
+ import { Events } from 'discord.js';
2
+ import type { Event } from './index.js';
3
+
4
+ export default {
5
+ name: Events.ClientReady,
6
+ once: true,
7
+ async execute(client) {
8
+ console.log(`Ready! Logged in as ${client.user.tag}`);
9
+ },
10
+ } satisfies Event<'ready'>;
@@ -0,0 +1,17 @@
1
+ import { URL } from 'node:url';
2
+ import { Client, GatewayIntentBits } from 'discord.js';
3
+ import { loadCommands, loadEvents } from './util/loaders.js';
4
+ import { registerEvents } from './util/registerEvents.js';
5
+
6
+ // Initialize the client
7
+ const client = new Client({ intents: [GatewayIntentBits.Guilds] });
8
+
9
+ // Load the events and commands
10
+ const events = await loadEvents(new URL('events/', import.meta.url));
11
+ const commands = await loadCommands(new URL('commands/', import.meta.url));
12
+
13
+ // Register the event handlers
14
+ registerEvents(commands, events, client);
15
+
16
+ // Login to the client
17
+ void client.login();
@@ -0,0 +1,15 @@
1
+ import process from 'node:process';
2
+ import { URL } from 'node:url';
3
+ import { API } from '@discordjs/core/http-only';
4
+ import { REST } from 'discord.js';
5
+ import { loadCommands } from './loaders.js';
6
+
7
+ const commands = await loadCommands(new URL('commands/', import.meta.url));
8
+ const commandData = [...commands.values()].map((command) => command.data);
9
+
10
+ const rest = new REST({ version: '10' }).setToken(process.env.TOKEN!);
11
+ const api = new API(rest);
12
+
13
+ const result = await api.applicationCommands.bulkOverwriteGlobalCommands(process.env.APPLICATION_ID!, commandData);
14
+
15
+ console.log(`Successfully registered ${result.length} commands.`);
@@ -0,0 +1,76 @@
1
+ import type { PathLike } from 'node:fs';
2
+ import { readdir, stat } from 'node:fs/promises';
3
+ import { URL } from 'node:url';
4
+ import type { Command } from '../commands/index.js';
5
+ import { predicate as commandPredicate } from '../commands/index.js';
6
+ import type { Event } from '../events/index.js';
7
+ import { predicate as eventPredicate } from '../events/index.js';
8
+
9
+ /**
10
+ * A predicate to check if the structure is valid
11
+ */
12
+ export type StructurePredicate<T> = (structure: unknown) => structure is T;
13
+
14
+ /**
15
+ * Loads all the structures in the provided directory
16
+ *
17
+ * @param dir - The directory to load the structures from
18
+ * @param predicate - The predicate to check if the structure is valid
19
+ * @param recursive - Whether to recursively load the structures in the directory
20
+ * @returns
21
+ */
22
+ export async function loadStructures<T>(
23
+ dir: PathLike,
24
+ predicate: StructurePredicate<T>,
25
+ recursive = true,
26
+ ): Promise<T[]> {
27
+ // Get the stats of the directory
28
+ const statDir = await stat(dir);
29
+
30
+ // If the provided directory path is not a directory, throw an error
31
+ if (!statDir.isDirectory()) {
32
+ throw new Error(`The directory '${dir}' is not a directory.`);
33
+ }
34
+
35
+ // Get all the files in the directory
36
+ const files = await readdir(dir);
37
+
38
+ // Create an empty array to store the structures
39
+ const structures: T[] = [];
40
+
41
+ // Loop through all the files in the directory
42
+ for (const file of files) {
43
+ // If the file is index.js or the file does not end with .js, skip the file
44
+ if (file === 'index.js' || !file.endsWith('.js')) {
45
+ continue;
46
+ }
47
+
48
+ // Get the stats of the file
49
+ const statFile = await stat(new URL(`${dir}/${file}`));
50
+
51
+ // If the file is a directory and recursive is true, recursively load the structures in the directory
52
+ if (statFile.isDirectory() && recursive) {
53
+ structures.push(...(await loadStructures(`${dir}/${file}`, predicate, recursive)));
54
+ continue;
55
+ }
56
+
57
+ // Import the structure dynamically from the file
58
+ const structure = (await import(`${dir}/${file}`)).default;
59
+
60
+ // If the structure is a valid structure, add it
61
+ if (predicate(structure)) structures.push(structure);
62
+ }
63
+
64
+ return structures;
65
+ }
66
+
67
+ export async function loadCommands(dir: PathLike, recursive = true): Promise<Map<string, Command>> {
68
+ return (await loadStructures(dir, commandPredicate, recursive)).reduce(
69
+ (acc, cur) => acc.set(cur.data.name, cur),
70
+ new Map<string, Command>(),
71
+ );
72
+ }
73
+
74
+ export async function loadEvents(dir: PathLike, recursive = true): Promise<Event[]> {
75
+ return loadStructures(dir, eventPredicate, recursive);
76
+ }
@@ -0,0 +1,25 @@
1
+ import { Events, type Client } from 'discord.js';
2
+ import type { Command } from '../commands/index.js';
3
+ import type { Event } from '../events/index.js';
4
+
5
+ export function registerEvents(commands: Map<string, Command>, events: Event[], client: Client): void {
6
+ // Create an event to handle command interactions
7
+ const interactionCreateEvent: Event<Events.InteractionCreate> = {
8
+ name: Events.InteractionCreate,
9
+ async execute(interaction) {
10
+ if (interaction.isCommand()) {
11
+ const command = commands.get(interaction.commandName);
12
+
13
+ if (!command) {
14
+ throw new Error(`Command '${interaction.commandName}' not found.`);
15
+ }
16
+
17
+ await command.execute(interaction);
18
+ }
19
+ },
20
+ };
21
+
22
+ for (const event of [...events, interactionCreateEvent]) {
23
+ client[event.once ? 'once' : 'on'](event.name, async (...args) => event.execute(...args));
24
+ }
25
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "allowJs": true
5
+ },
6
+ "include": ["**/*.ts", "**/*.js", "**/*.test.ts", "**/*.test.js"],
7
+ "exclude": []
8
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "@sapphire/ts-config/extra-strict",
3
+ "compilerOptions": {
4
+ "declaration": false,
5
+ "declarationMap": false,
6
+ "module": "ESNext",
7
+ "moduleResolution": "NodeNext",
8
+ "target": "ESNext",
9
+ "outDir": "dist"
10
+ }
11
+ }