create-discord-bot 0.2.0 → 0.2.2
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 +8 -1
- package/dist/index.js +2 -0
- package/package.json +29 -25
- package/template/Bun/JavaScript/package.json +24 -0
- package/template/Bun/TypeScript/package.json +26 -0
- package/template/Bun/TypeScript/tsconfig.eslint.json +8 -0
- package/template/Bun/TypeScript/tsconfig.json +16 -0
- package/template/Deno/.env +2 -0
- package/template/Deno/.prettierrc.json +9 -0
- package/template/Deno/.vscode/extensions.json +3 -0
- package/template/Deno/.vscode/settings.json +15 -0
- package/template/Deno/deno.jsonc +41 -0
- package/template/Deno/src/commands/index.ts +27 -0
- package/template/Deno/src/commands/ping.ts +11 -0
- package/template/Deno/src/events/index.ts +33 -0
- package/template/Deno/src/events/ready.ts +10 -0
- package/template/Deno/src/index.ts +18 -0
- package/template/Deno/src/util/deploy.ts +15 -0
- package/template/Deno/src/util/loaders.ts +76 -0
- package/template/Deno/src/util/registerEvents.ts +25 -0
- package/template/JavaScript/.eslintrc.json +1 -0
- package/template/JavaScript/.prettierrc.json +1 -0
- package/template/JavaScript/.vscode/extensions.json +10 -0
- package/template/JavaScript/.vscode/settings.json +13 -0
- package/template/JavaScript/package.json +10 -9
- package/template/JavaScript/src/index.js +2 -1
- package/template/JavaScript/src/util/deploy.js +2 -2
- package/template/TypeScript/.eslintrc.json +5 -1
- package/template/TypeScript/.prettierrc.json +1 -0
- package/template/TypeScript/.vscode/extensions.json +10 -0
- package/template/TypeScript/.vscode/settings.json +13 -0
- package/template/TypeScript/package.json +14 -13
- package/template/TypeScript/src/commands/index.ts +1 -1
- package/template/TypeScript/src/commands/ping.ts +1 -1
- package/template/TypeScript/src/events/index.ts +1 -1
- package/template/TypeScript/src/events/ready.ts +2 -2
- package/template/TypeScript/src/index.ts +4 -3
- package/template/TypeScript/src/util/deploy.ts +3 -3
- package/template/TypeScript/src/util/loaders.ts +6 -6
- package/template/TypeScript/src/util/registerEvents.ts +2 -2
- package/template/TypeScript/tsconfig.eslint.json +2 -2
- package/template/TypeScript/tsconfig.json +4 -2
- package/CHANGELOG.md +0 -28
- package/dist/index.mjs +0 -4
package/README.md
CHANGED
|
@@ -16,7 +16,14 @@
|
|
|
16
16
|
|
|
17
17
|
## About
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
It's easy to create a simple Discord bot to begin your journey with the Discord API.
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm create discord-bot ./your/chosen/directory
|
|
23
|
+
yarn create discord-bot ./your/chosen/directory
|
|
24
|
+
pnpm create discord-bot ./your/chosen/directory
|
|
25
|
+
bunx create-discord-bot ./your/chosen/directory
|
|
26
|
+
```
|
|
20
27
|
|
|
21
28
|
## Links
|
|
22
29
|
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __defProp=Object.defineProperty,__name=(target,value)=>__defProp(target,"name",{value:value,configurable:!0});import process3 from"node:process";import{Option,program}from"commander";import{red,yellow,green}from"picocolors";import prompts from"prompts";import validateProjectName from"validate-npm-package-name";var package_default_name="create-discord-bot",package_default_version="0.2.2";import{cp,stat,mkdir,readdir,readFile,writeFile}from"node:fs/promises";import path from"node:path";import process2 from"node:process";import{URL}from"node:url";import glob from"fast-glob";import picocolors2 from"picocolors";import{execSync}from"node:child_process";import process from"node:process";import picocolors from"picocolors";function resolvePackageManager(){const npmConfigUserAgent=process.env.npm_config_user_agent;return npmConfigUserAgent?npmConfigUserAgent.startsWith("npm")?"npm":npmConfigUserAgent.startsWith("yarn")?"yarn":npmConfigUserAgent.startsWith("pnpm")?"pnpm":npmConfigUserAgent.startsWith("bun")?"bun":(console.error(picocolors.yellow(`Detected an unsupported package manager (${npmConfigUserAgent}). Falling back to npm.`)),"npm"):"npm"}function install(packageManager2){let installCommand=`${packageManager2} install`;switch(console.log(`Installing dependencies with ${packageManager2}...`),packageManager2){case"yarn":console.log(),installCommand=[`${packageManager2} set version stable`,`${packageManager2} config set nodeLinker node-modules`,`${packageManager2} config set logFilters --json '[{ "code": "YN0002", "level": "discard" }, { "code": "YN0013", "level": "discard" }, { "code": "YN0032", "level": "discard" }, { "code": "YN0060", "level": "discard" }]'`,`${packageManager2} plugin import interactive-tools`,`${packageManager2} plugin import workspace-tools`,installCommand];break;case"deno":installCommand=`${packageManager2} cache --reload src/index.ts`;break;case"pnpm":case"bun":console.log()}const env={...process.env,ADBLOCK:"1",NODE_ENV:"development",DISABLE_OPENCOLLECTIVE:"1"};if(Array.isArray(installCommand))for(const[index,command]of installCommand.entries()){if(index===installCommand.length-1){execSync(command,{stdio:"inherit",env:env});break}execSync(command,{stdio:"ignore",env:env})}else execSync(installCommand,{stdio:"inherit",env:env})}async function createDiscordBot({directory:directory,installPackages:installPackages2,typescript:typescript2,packageManager:packageManager2}){const root=path.resolve(directory),directoryName=path.basename(root);console.log();(!(await stat(root).catch((async error=>{if("ENOENT"===error.code)return await mkdir(root,{recursive:!0}),stat(root);throw error}))).isDirectory()||(await readdir(root)).length>0)&&(console.error(picocolors2.red(`The directory ${picocolors2.yellow(`"${directoryName}"`)} is either not a directory or is not empty.`)),console.error(picocolors2.red("Please specify an empty directory.")),process2.exit(1)),console.log(`Creating ${directoryName} in ${picocolors2.green(root)}.`);const deno2="deno"===packageManager2;await cp(new URL("../template/"+(deno2?"Deno":typescript2?"TypeScript":"JavaScript"),import.meta.url),root,{recursive:!0});const bun="bun"===packageManager2;bun&&(await cp(new URL(`../template/Bun/${typescript2?"TypeScript":"JavaScript"}/package.json`,import.meta.url),`${root}/package.json`),typescript2&&(await cp(new URL("../template/Bun/Typescript/tsconfig.eslint.json",import.meta.url),`${root}/tsconfig.eslint.json`),await cp(new URL("../template/Bun/Typescript/tsconfig.json",import.meta.url),`${root}/tsconfig.json`))),process2.chdir(root);const newVSCodeSettings=await readFile("./.vscode/settings.json",{encoding:"utf8"}).then((str=>{let newStr=str.replace("[REPLACE_ME]",deno2||bun?"auto":packageManager2);return deno2&&(newStr=newStr.replaceAll('"[REPLACE_BOOL]"',!0)),newStr}));await writeFile("./.vscode/settings.json",newVSCodeSettings);const globStream=glob.stream("./src/**/*.ts");for await(const file of globStream){const newData=await readFile(file,{encoding:"utf8"}).then((str=>str.replaceAll("[REPLACE_IMPORT_EXT]",typescript2?"ts":"js")));await writeFile(file,newData)}if(!deno2){const newPackageJSON=await readFile("./package.json",{encoding:"utf8"}).then((str=>{let newStr=str.replace("[REPLACE_ME]",directoryName);return newStr=newStr.replaceAll("[REPLACE_IMPORT_EXT]",typescript2?"ts":"js"),newStr}));await writeFile("./package.json",newPackageJSON)}if(installPackages2)try{install(packageManager2)}catch(error){console.log();"SIGINT"===error.signal?console.log(picocolors2.red("Installation aborted.")):(console.error(picocolors2.red("Installation failed.")),process2.exit(1))}console.log(),console.log(picocolors2.green("All done! Be sure to read through the discord.js guide for help on your journey.")),console.log(`Link: ${picocolors2.cyan("https://guide.discordjs.dev")}`)}__name(resolvePackageManager,"resolvePackageManager"),__name(install,"install"),__name(createDiscordBot,"createDiscordBot");var projectDirectory="",handleSigTerm=__name((()=>process3.exit(0)),"handleSigTerm");process3.on("SIGINT",handleSigTerm),process3.on("SIGTERM",handleSigTerm);var onPromptState=__name((state=>{state.aborted&&(process3.stdout.write("[?25h"),process3.stdout.write("\n"),process3.exit(1))}),"onPromptState");program.name(package_default_name).version(package_default_version).description("Create a basic discord.js bot.").argument("[directory]","What is the name of the directory you want to create this project in?").usage(`${green("<directory>")}`).action((directory=>{projectDirectory=directory})).option("--typescript","Whether to use the TypeScript template.").option("--javascript","Whether to use the JavaScript template.").option("--no-install","Whether to not automatically install the packages.").addOption(new Option("--package-manager <packageManager>","The package manager to use.").choices(["npm","pnpm","yarn","bun","deno"]).default(resolvePackageManager())).allowUnknownOption().parse();var{typescript:typescript,javascript:javascript,packageManager:packageManager,install:installPackages}=program.opts();if(projectDirectory||(projectDirectory=(await prompts({onState:onPromptState,type:"text",name:"directory",initial:"my-bot",message:"What is the name of the directory you want to create this project in?",validate:directory=>{const validationResult=validateProjectName(directory);if(!validationResult.validForNewPackages){const errors=[];for(const error of[...validationResult.errors??[],...validationResult.warnings??[]])errors.push(red(`- ${error}`));return red(`Cannot create a project named ${yellow(`"${directory}"`)} due to npm naming restrictions.\n\nErrors:\n${errors.join("\n")}\n\n${red("\nSee https://docs.npmjs.com/cli/configuring-npm/package-json for more details.")}}`)}return!0}})).directory),!("deno"===packageManager)&&void 0===typescript&&void 0===javascript){const{useTypescript:useTypescript}=await prompts({onState:onPromptState,type:"toggle",name:"useTypescript",message:"Do you want to use TypeScript?",initial:!0,active:"Yes",inactive:"No"});typescript=useTypescript}await createDiscordBot({typescript:typescript,directory:projectDirectory,packageManager:packageManager,installPackages:installPackages});
|
package/package.json
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
2
3
|
"name": "create-discord-bot",
|
|
3
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.2",
|
|
4
5
|
"description": "A simple way to create a startup Discord bot.",
|
|
5
|
-
"
|
|
6
|
-
|
|
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",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": "./dist/index.js",
|
|
14
8
|
"directories": {
|
|
9
|
+
"bin": "bin",
|
|
15
10
|
"lib": "src"
|
|
16
11
|
},
|
|
17
12
|
"files": [
|
|
@@ -45,31 +40,40 @@
|
|
|
45
40
|
},
|
|
46
41
|
"homepage": "https://discord.js.org",
|
|
47
42
|
"dependencies": {
|
|
48
|
-
"
|
|
49
|
-
"
|
|
43
|
+
"commander": "^11.1.0",
|
|
44
|
+
"fast-glob": "^3.3.2",
|
|
45
|
+
"picocolors": "^1.0.0",
|
|
50
46
|
"prompts": "^2.4.2",
|
|
51
47
|
"validate-npm-package-name": "^5.0.0"
|
|
52
48
|
},
|
|
53
49
|
"devDependencies": {
|
|
54
|
-
"@favware/cliff-jumper": "^2.
|
|
55
|
-
"@
|
|
56
|
-
"@types/
|
|
57
|
-
"@types/
|
|
58
|
-
"@
|
|
59
|
-
"@vitest/coverage-c8": "^0.33.0",
|
|
50
|
+
"@favware/cliff-jumper": "^2.2.1",
|
|
51
|
+
"@types/node": "18.18.8",
|
|
52
|
+
"@types/prompts": "^2.4.8",
|
|
53
|
+
"@types/validate-npm-package-name": "^4.0.2",
|
|
54
|
+
"@vitest/coverage-v8": "^0.34.6",
|
|
60
55
|
"cross-env": "^7.0.3",
|
|
61
|
-
"eslint": "^8.
|
|
62
|
-
"eslint-config-neon": "^0.1.
|
|
56
|
+
"eslint": "^8.53.0",
|
|
57
|
+
"eslint-config-neon": "^0.1.57",
|
|
63
58
|
"eslint-formatter-pretty": "^5.0.0",
|
|
64
|
-
"prettier": "^
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
59
|
+
"prettier": "^3.0.3",
|
|
60
|
+
"terser": "^5.24.0",
|
|
61
|
+
"tsup": "^7.2.0",
|
|
62
|
+
"typescript": "^5.2.2",
|
|
63
|
+
"vitest": "^0.34.6",
|
|
64
|
+
"@discordjs/api-extractor": "^7.38.1"
|
|
68
65
|
},
|
|
69
66
|
"engines": {
|
|
70
|
-
"node": ">=18
|
|
67
|
+
"node": ">=18"
|
|
71
68
|
},
|
|
72
69
|
"publishConfig": {
|
|
73
70
|
"access": "public"
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "tsc --noEmit && tsup",
|
|
74
|
+
"lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty src",
|
|
75
|
+
"format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty src",
|
|
76
|
+
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/create-discord-bot/*'",
|
|
77
|
+
"release": "cliff-jumper"
|
|
74
78
|
}
|
|
75
79
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
+
"name": "[REPLACE_ME]",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"private": true,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"lint": "prettier --check . && eslint --ext .[REPLACE_IMPORT_EXT] --format=pretty src",
|
|
9
|
+
"deploy": "bun run src/util/deploy.[REPLACE_IMPORT_EXT]",
|
|
10
|
+
"format": "prettier --write . && eslint --ext .[REPLACE_IMPORT_EXT] --fix --format=pretty src",
|
|
11
|
+
"start": "bun run src/index.[REPLACE_IMPORT_EXT]"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@discordjs/core": "^1.0.1",
|
|
15
|
+
"discord.js": "^14.13.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@sapphire/ts-config": "^4.0.1",
|
|
19
|
+
"eslint": "^8.53.0",
|
|
20
|
+
"eslint-config-neon": "^0.1.57",
|
|
21
|
+
"eslint-formatter-pretty": "^5.0.0",
|
|
22
|
+
"prettier": "^3.0.3"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
+
"name": "[REPLACE_ME]",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"private": true,
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"lint": "tsc && prettier --check . && eslint --ext .[REPLACE_IMPORT_EXT] --format=pretty src",
|
|
9
|
+
"deploy": "bun run src/util/deploy.[REPLACE_IMPORT_EXT]",
|
|
10
|
+
"format": "prettier --write . && eslint --ext .[REPLACE_IMPORT_EXT] --fix --format=pretty src",
|
|
11
|
+
"start": "bun run src/index.[REPLACE_IMPORT_EXT]"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@discordjs/core": "^1.0.1",
|
|
15
|
+
"discord.js": "^14.13.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@sapphire/ts-config": "^5.0.0",
|
|
19
|
+
"bun-types": "^1.0.9",
|
|
20
|
+
"eslint": "^8.53.0",
|
|
21
|
+
"eslint-config-neon": "^0.1.57",
|
|
22
|
+
"eslint-formatter-pretty": "^5.0.0",
|
|
23
|
+
"prettier": "^3.0.3",
|
|
24
|
+
"typescript": "^5.2.2"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig.json",
|
|
3
|
+
"extends": "@sapphire/ts-config/extra-strict",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"declaration": false,
|
|
6
|
+
"declarationMap": false,
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"moduleResolution": "Bundler",
|
|
9
|
+
"target": "ESNext",
|
|
10
|
+
"outDir": "dist",
|
|
11
|
+
"noEmit": true,
|
|
12
|
+
"allowImportingTsExtensions": true,
|
|
13
|
+
"types": ["bun-types"],
|
|
14
|
+
"skipLibCheck": true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"editor.defaultFormatter": "denoland.vscode-deno",
|
|
3
|
+
"editor.formatOnSave": true,
|
|
4
|
+
"editor.codeActionsOnSave": {
|
|
5
|
+
"source.fixAll": true,
|
|
6
|
+
"source.organizeImports": false
|
|
7
|
+
},
|
|
8
|
+
"editor.trimAutoWhitespace": false,
|
|
9
|
+
"files.insertFinalNewline": true,
|
|
10
|
+
"files.eol": "\n",
|
|
11
|
+
"npm.packageManager": "[REPLACE_ME]",
|
|
12
|
+
"deno.enable": "[REPLACE_BOOL]",
|
|
13
|
+
"deno.lint": "[REPLACE_BOOL]",
|
|
14
|
+
"deno.unstable": false
|
|
15
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/denoland/deno/main/cli/schemas/config-file.v1.json",
|
|
3
|
+
"tasks": {
|
|
4
|
+
"lint": "deno lint",
|
|
5
|
+
"deploy": "deno run --allow-read --allow-env --allow-net src/util/deploy.ts",
|
|
6
|
+
"format": "deno fmt",
|
|
7
|
+
"fmt": "deno fmt",
|
|
8
|
+
"start": "deno run --allow-read --allow-env --allow-net src/index.ts"
|
|
9
|
+
},
|
|
10
|
+
"lint": {
|
|
11
|
+
"include": ["src/"],
|
|
12
|
+
"rules": {
|
|
13
|
+
"tags": ["recommended"],
|
|
14
|
+
"exclude": ["require-await", "no-await-in-sync-fn"]
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"fmt": {
|
|
18
|
+
"useTabs": true,
|
|
19
|
+
"lineWidth": 120,
|
|
20
|
+
"semiColons": true,
|
|
21
|
+
"singleQuote": true,
|
|
22
|
+
"proseWrap": "preserve",
|
|
23
|
+
"include": ["src/"]
|
|
24
|
+
},
|
|
25
|
+
"compilerOptions": {
|
|
26
|
+
"alwaysStrict": true,
|
|
27
|
+
"emitDecoratorMetadata": true,
|
|
28
|
+
"verbatimModuleSyntax": true,
|
|
29
|
+
"lib": ["deno.window"],
|
|
30
|
+
"noFallthroughCasesInSwitch": true,
|
|
31
|
+
"noImplicitReturns": true,
|
|
32
|
+
"noUnusedLocals": true,
|
|
33
|
+
"noUnusedParameters": true,
|
|
34
|
+
"removeComments": false,
|
|
35
|
+
"strict": true,
|
|
36
|
+
"allowUnreachableCode": false,
|
|
37
|
+
"allowUnusedLabels": false,
|
|
38
|
+
"exactOptionalPropertyTypes": false,
|
|
39
|
+
"noImplicitOverride": true
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { RESTPostAPIApplicationCommandsJSONBody, CommandInteraction } from 'npm:discord.js@^14.13.0';
|
|
2
|
+
import type { StructurePredicate } from '../util/loaders.ts';
|
|
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,33 @@
|
|
|
1
|
+
import type { ClientEvents } from 'npm:discord.js@^14.13.0';
|
|
2
|
+
import type { StructurePredicate } from '../util/loaders.ts';
|
|
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 'npm:discord.js@^14.13.0';
|
|
2
|
+
import type { Event } from './index.ts';
|
|
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<Events.ClientReady>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import 'https://deno.land/std@0.199.0/dotenv/load.ts';
|
|
2
|
+
import { URL } from 'node:url';
|
|
3
|
+
import { Client, GatewayIntentBits } from 'npm:discord.js@^14.13.0';
|
|
4
|
+
import { loadCommands, loadEvents } from './util/loaders.ts';
|
|
5
|
+
import { registerEvents } from './util/registerEvents.ts';
|
|
6
|
+
|
|
7
|
+
// Initialize the client
|
|
8
|
+
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
|
9
|
+
|
|
10
|
+
// Load the events and commands
|
|
11
|
+
const events = await loadEvents(new URL('events/', import.meta.url));
|
|
12
|
+
const commands = await loadCommands(new URL('commands/', import.meta.url));
|
|
13
|
+
|
|
14
|
+
// Register the event handlers
|
|
15
|
+
registerEvents(commands, events, client);
|
|
16
|
+
|
|
17
|
+
// Login to the client
|
|
18
|
+
void client.login(Deno.env.get('DISCORD_TOKEN'));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import 'https://deno.land/std@0.199.0/dotenv/load.ts';
|
|
2
|
+
import { URL } from 'node:url';
|
|
3
|
+
import { API } from 'npm:@discordjs/core@^1.0.1/http-only';
|
|
4
|
+
import { REST } from 'npm:discord.js@^14.13.0';
|
|
5
|
+
import { loadCommands } from './loaders.ts';
|
|
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(Deno.env.get('DISCORD_TOKEN')!);
|
|
11
|
+
const api = new API(rest);
|
|
12
|
+
|
|
13
|
+
const result = await api.applicationCommands.bulkOverwriteGlobalCommands(Deno.env.get('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.ts';
|
|
5
|
+
import { predicate as commandPredicate } from '../commands/index.ts';
|
|
6
|
+
import type { Event } from '../events/index.ts';
|
|
7
|
+
import { predicate as eventPredicate } from '../events/index.ts';
|
|
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.ts' || !file.endsWith('.ts')) {
|
|
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 'npm:discord.js@^14.13.0';
|
|
2
|
+
import type { Command } from '../commands/index.ts';
|
|
3
|
+
import type { Event } from '../events/index.ts';
|
|
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,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
|
|
3
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
4
|
+
"editor.formatOnSave": true,
|
|
5
|
+
"editor.codeActionsOnSave": {
|
|
6
|
+
"source.fixAll": true,
|
|
7
|
+
"source.organizeImports": false
|
|
8
|
+
},
|
|
9
|
+
"editor.trimAutoWhitespace": false,
|
|
10
|
+
"files.insertFinalNewline": true,
|
|
11
|
+
"files.eol": "\n",
|
|
12
|
+
"npm.packageManager": "[REPLACE_ME]"
|
|
13
|
+
}
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
+
"name": "[REPLACE_ME]",
|
|
3
4
|
"version": "0.1.0",
|
|
4
5
|
"private": true,
|
|
5
6
|
"type": "module",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"lint": "prettier --check . && eslint
|
|
8
|
-
"format": "prettier --write . && eslint
|
|
8
|
+
"lint": "prettier --check . && eslint --ext .js,.mjs,.cjs --format=pretty src",
|
|
9
|
+
"format": "prettier --write . && eslint --ext .js,.mjs,.cjs --fix --format=pretty src",
|
|
9
10
|
"start": "node --require dotenv/config src/index.js",
|
|
10
11
|
"deploy": "node --require dotenv/config src/util/deploy.js"
|
|
11
12
|
},
|
|
12
13
|
"dependencies": {
|
|
13
|
-
"@discordjs/core": "^0.
|
|
14
|
-
"discord.js": "^14.
|
|
15
|
-
"dotenv": "^16.
|
|
14
|
+
"@discordjs/core": "^1.0.1",
|
|
15
|
+
"discord.js": "^14.13.0",
|
|
16
|
+
"dotenv": "^16.3.1"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
|
-
"eslint": "^8.
|
|
19
|
-
"eslint-config-neon": "^0.1.
|
|
19
|
+
"eslint": "^8.53.0",
|
|
20
|
+
"eslint-config-neon": "^0.1.57",
|
|
20
21
|
"eslint-formatter-pretty": "^5.0.0",
|
|
21
|
-
"prettier": "^
|
|
22
|
+
"prettier": "^3.0.3"
|
|
22
23
|
}
|
|
23
24
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
1
2
|
import { URL } from 'node:url';
|
|
2
3
|
import { Client, GatewayIntentBits } from 'discord.js';
|
|
3
4
|
import { loadCommands, loadEvents } from './util/loaders.js';
|
|
@@ -14,4 +15,4 @@ const commands = await loadCommands(new URL('commands/', import.meta.url));
|
|
|
14
15
|
registerEvents(commands, events, client);
|
|
15
16
|
|
|
16
17
|
// Login to the client
|
|
17
|
-
void client.login();
|
|
18
|
+
void client.login(process.env.DISCORD_TOKEN);
|
|
@@ -4,10 +4,10 @@ import { API } from '@discordjs/core/http-only';
|
|
|
4
4
|
import { REST } from 'discord.js';
|
|
5
5
|
import { loadCommands } from './loaders.js';
|
|
6
6
|
|
|
7
|
-
const commands = await loadCommands(new URL('commands/', import.meta.url));
|
|
7
|
+
const commands = await loadCommands(new URL('../commands/', import.meta.url));
|
|
8
8
|
const commandData = [...commands.values()].map((command) => command.data);
|
|
9
9
|
|
|
10
|
-
const rest = new REST({ version: '10' }).setToken(process.env.
|
|
10
|
+
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN);
|
|
11
11
|
const api = new API(rest);
|
|
12
12
|
|
|
13
13
|
const result = await api.applicationCommands.bulkOverwriteGlobalCommands(process.env.APPLICATION_ID, commandData);
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/eslintrc.json",
|
|
2
3
|
"root": true,
|
|
3
4
|
"extends": ["neon/common", "neon/node", "neon/typescript", "neon/prettier"],
|
|
4
5
|
"parserOptions": {
|
|
5
6
|
"project": ["./tsconfig.eslint.json"]
|
|
6
7
|
},
|
|
7
|
-
"ignorePatterns": ["dist/*"]
|
|
8
|
+
"ignorePatterns": ["**/dist/*"],
|
|
9
|
+
"rules": {
|
|
10
|
+
"import/extensions": 0
|
|
11
|
+
}
|
|
8
12
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
|
|
3
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
|
4
|
+
"editor.formatOnSave": true,
|
|
5
|
+
"editor.codeActionsOnSave": {
|
|
6
|
+
"source.fixAll": true,
|
|
7
|
+
"source.organizeImports": false
|
|
8
|
+
},
|
|
9
|
+
"editor.trimAutoWhitespace": false,
|
|
10
|
+
"files.insertFinalNewline": true,
|
|
11
|
+
"files.eol": "\n",
|
|
12
|
+
"npm.packageManager": "[REPLACE_ME]"
|
|
13
|
+
}
|
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
+
"name": "[REPLACE_ME]",
|
|
3
4
|
"version": "0.1.0",
|
|
4
5
|
"private": true,
|
|
5
6
|
"type": "module",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"lint": "prettier --check . && eslint
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"lint": "prettier --check . && eslint --ext .ts --format=pretty src",
|
|
9
10
|
"deploy": "node --require dotenv/config dist/util/deploy.js",
|
|
10
|
-
"format": "prettier --write . && eslint
|
|
11
|
+
"format": "prettier --write . && eslint --ext .ts --fix --format=pretty src",
|
|
11
12
|
"start": "node --require dotenv/config dist/index.js"
|
|
12
13
|
},
|
|
13
14
|
"dependencies": {
|
|
14
|
-
"@discordjs/core": "^0.
|
|
15
|
-
"discord.js": "^14.
|
|
16
|
-
"dotenv": "^16.
|
|
15
|
+
"@discordjs/core": "^1.0.1",
|
|
16
|
+
"discord.js": "^14.13.0",
|
|
17
|
+
"dotenv": "^16.3.1"
|
|
17
18
|
},
|
|
18
19
|
"devDependencies": {
|
|
19
|
-
"@sapphire/ts-config": "^
|
|
20
|
-
"@types/node": "^18.
|
|
21
|
-
"eslint": "^8.
|
|
22
|
-
"eslint-config-neon": "^0.1.
|
|
20
|
+
"@sapphire/ts-config": "^5.0.0",
|
|
21
|
+
"@types/node": "^18.18.8",
|
|
22
|
+
"eslint": "^8.53.0",
|
|
23
|
+
"eslint-config-neon": "^0.1.57",
|
|
23
24
|
"eslint-formatter-pretty": "^5.0.0",
|
|
24
|
-
"prettier": "^
|
|
25
|
-
"typescript": "^5.
|
|
25
|
+
"prettier": "^3.0.3",
|
|
26
|
+
"typescript": "^5.2.2"
|
|
26
27
|
}
|
|
27
28
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RESTPostAPIApplicationCommandsJSONBody, CommandInteraction } from 'discord.js';
|
|
2
|
-
import type { StructurePredicate } from '../util/loaders.
|
|
2
|
+
import type { StructurePredicate } from '../util/loaders.[REPLACE_IMPORT_EXT]';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Defines the structure of a command
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Events } from 'discord.js';
|
|
2
|
-
import type { Event } from './index.
|
|
2
|
+
import type { Event } from './index.[REPLACE_IMPORT_EXT]';
|
|
3
3
|
|
|
4
4
|
export default {
|
|
5
5
|
name: Events.ClientReady,
|
|
@@ -7,4 +7,4 @@ export default {
|
|
|
7
7
|
async execute(client) {
|
|
8
8
|
console.log(`Ready! Logged in as ${client.user.tag}`);
|
|
9
9
|
},
|
|
10
|
-
} satisfies Event<
|
|
10
|
+
} satisfies Event<Events.ClientReady>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
1
2
|
import { URL } from 'node:url';
|
|
2
3
|
import { Client, GatewayIntentBits } from 'discord.js';
|
|
3
|
-
import { loadCommands, loadEvents } from './util/loaders.
|
|
4
|
-
import { registerEvents } from './util/registerEvents.
|
|
4
|
+
import { loadCommands, loadEvents } from './util/loaders.[REPLACE_IMPORT_EXT]';
|
|
5
|
+
import { registerEvents } from './util/registerEvents.[REPLACE_IMPORT_EXT]';
|
|
5
6
|
|
|
6
7
|
// Initialize the client
|
|
7
8
|
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
|
@@ -14,4 +15,4 @@ const commands = await loadCommands(new URL('commands/', import.meta.url));
|
|
|
14
15
|
registerEvents(commands, events, client);
|
|
15
16
|
|
|
16
17
|
// Login to the client
|
|
17
|
-
void client.login();
|
|
18
|
+
void client.login(process.env.DISCORD_TOKEN);
|
|
@@ -2,12 +2,12 @@ import process from 'node:process';
|
|
|
2
2
|
import { URL } from 'node:url';
|
|
3
3
|
import { API } from '@discordjs/core/http-only';
|
|
4
4
|
import { REST } from 'discord.js';
|
|
5
|
-
import { loadCommands } from './loaders.
|
|
5
|
+
import { loadCommands } from './loaders.[REPLACE_IMPORT_EXT]';
|
|
6
6
|
|
|
7
|
-
const commands = await loadCommands(new URL('commands/', import.meta.url));
|
|
7
|
+
const commands = await loadCommands(new URL('../commands/', import.meta.url));
|
|
8
8
|
const commandData = [...commands.values()].map((command) => command.data);
|
|
9
9
|
|
|
10
|
-
const rest = new REST({ version: '10' }).setToken(process.env.
|
|
10
|
+
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN!);
|
|
11
11
|
const api = new API(rest);
|
|
12
12
|
|
|
13
13
|
const result = await api.applicationCommands.bulkOverwriteGlobalCommands(process.env.APPLICATION_ID!, commandData);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { PathLike } from 'node:fs';
|
|
2
2
|
import { readdir, stat } from 'node:fs/promises';
|
|
3
3
|
import { URL } from 'node:url';
|
|
4
|
-
import type { Command } from '../commands/index.
|
|
5
|
-
import { predicate as commandPredicate } from '../commands/index.
|
|
6
|
-
import type { Event } from '../events/index.
|
|
7
|
-
import { predicate as eventPredicate } from '../events/index.
|
|
4
|
+
import type { Command } from '../commands/index.[REPLACE_IMPORT_EXT]';
|
|
5
|
+
import { predicate as commandPredicate } from '../commands/index.[REPLACE_IMPORT_EXT]';
|
|
6
|
+
import type { Event } from '../events/index.[REPLACE_IMPORT_EXT]';
|
|
7
|
+
import { predicate as eventPredicate } from '../events/index.[REPLACE_IMPORT_EXT]';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* A predicate to check if the structure is valid
|
|
@@ -40,8 +40,8 @@ export async function loadStructures<T>(
|
|
|
40
40
|
|
|
41
41
|
// Loop through all the files in the directory
|
|
42
42
|
for (const file of files) {
|
|
43
|
-
// If the file is index.
|
|
44
|
-
if (file === 'index.
|
|
43
|
+
// If the file is index.[REPLACE_IMPORT_EXT] or the file does not end with .[REPLACE_IMPORT_EXT], skip the file
|
|
44
|
+
if (file === 'index.[REPLACE_IMPORT_EXT]' || !file.endsWith('.[REPLACE_IMPORT_EXT]')) {
|
|
45
45
|
continue;
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Events, type Client } from 'discord.js';
|
|
2
|
-
import type { Command } from '../commands/index.
|
|
3
|
-
import type { Event } from '../events/index.
|
|
2
|
+
import type { Command } from '../commands/index.[REPLACE_IMPORT_EXT]';
|
|
3
|
+
import type { Event } from '../events/index.[REPLACE_IMPORT_EXT]';
|
|
4
4
|
|
|
5
5
|
export function registerEvents(commands: Map<string, Command>, events: Event[], client: Client): void {
|
|
6
6
|
// Create an event to handle command interactions
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig.json",
|
|
2
3
|
"extends": "./tsconfig.json",
|
|
3
4
|
"compilerOptions": {
|
|
4
5
|
"allowJs": true
|
|
5
6
|
},
|
|
6
|
-
"include": ["
|
|
7
|
-
"exclude": []
|
|
7
|
+
"include": ["*.ts", "*.tsx", "*.js", "*.cjs", "*.mjs", "src", "bin"]
|
|
8
8
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig.json",
|
|
2
3
|
"extends": "@sapphire/ts-config/extra-strict",
|
|
3
4
|
"compilerOptions": {
|
|
4
5
|
"declaration": false,
|
|
5
6
|
"declarationMap": false,
|
|
6
|
-
"module": "
|
|
7
|
+
"module": "NodeNext",
|
|
7
8
|
"moduleResolution": "NodeNext",
|
|
8
9
|
"target": "ESNext",
|
|
9
|
-
"outDir": "dist"
|
|
10
|
+
"outDir": "dist",
|
|
11
|
+
"skipLibCheck": true
|
|
10
12
|
}
|
|
11
13
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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/dist/index.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
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});
|