mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 04:23:31 +01:00
feat: create-discord-bot (#9420)
* feat: basic initialisation * fix: no scope * chore: add options for issues * feat: good word, Monbrey * feat: basic README.md * fix: no documentation for this * feat: install for them * chore: update licencing * chore: fix year * fix: build tsup * feat: add TypeScript option * feat: add `name` option * chore: ignore annoying errors * chore: add tsconfig.json * refactor: remove name We can just use the name of the directory instead. * chore: update cliff jumper rc * chore: bump dependencies * chore: bump dependencies * fix: build in prepack * fix: configure ESLint correctly * feat: infer package manager * docs(packageManager): document `install()` * fix(packageManager): do not emit a warning for `npm` * refactor: change project name colour to yellow * docs(constants): basic documentation * feat: add link * chore: add `verbatimModuleSyntax` * chore: bump discord.js * refactor: switch to @sapphire/ts-config * refactor: file name changes * refactor: tweak description * chore: update yarn.lock * fix: add .env * chore: bump dependencies * feat: event handler * refactor: use `default` * refactor: simpler event * chore: bump discord.js * fix: add release script and reorder * style: reorder package.json * chore: remove unneeded ignores * chore: bump minimum Node.js version * chore: add @types/node to TypeScript package.json * chore: apply requested changes Co-authored-by: Noel <buechler.noel@outlook.com> * style: run ESLint + Prettier * refactor: prefer "the" * refactor: remove some comments * feat: add ESLint + Prettier * chore: requested changes Co-authored-by: Noel <buechler.noel@outlook.com> * chore: more requested changes Co-authored-by: Noel <buechler.noel@outlook.com> --------- Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
1
packages/create-discord-bot/template/JavaScript/.env
Normal file
1
packages/create-discord-bot/template/JavaScript/.env
Normal file
@@ -0,0 +1 @@
|
||||
DISCORD_TOKEN=
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"root": true,
|
||||
"extends": ["neon/common", "neon/node", "neon/prettier"]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"quoteProps": "as-needed",
|
||||
"trailingComma": "all",
|
||||
"endOfLine": "lf"
|
||||
}
|
||||
21
packages/create-discord-bot/template/JavaScript/package.json
Normal file
21
packages/create-discord-bot/template/JavaScript/package.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "[REPLACE-NAME]",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"lint": "prettier --check . && eslint src --ext .js,.cjs --format=pretty",
|
||||
"format": "prettier --write . && eslint src --ext .js,.cjs --fix --format=pretty",
|
||||
"start": "node --require dotenv/config index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"discord.js": "^14.11.0",
|
||||
"dotenv": "^16.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.40.0",
|
||||
"eslint-config-neon": "^0.1.47",
|
||||
"eslint-formatter-pretty": "^5.0.0",
|
||||
"prettier": "^2.8.8"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Events } from 'discord.js';
|
||||
|
||||
export default {
|
||||
name: Events.ClientReady,
|
||||
once: true,
|
||||
async execute(client) {
|
||||
console.log(`Ready! Logged in as ${client.user.tag}`);
|
||||
},
|
||||
};
|
||||
15
packages/create-discord-bot/template/JavaScript/src/index.js
Normal file
15
packages/create-discord-bot/template/JavaScript/src/index.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { readdir } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath, URL } from 'node:url';
|
||||
import { Client, GatewayIntentBits } from 'discord.js';
|
||||
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
const eventsPath = fileURLToPath(new URL('events', import.meta.url));
|
||||
const eventFiles = await readdir(eventsPath).then((files) => files.filter((file) => file.endsWith('.js')));
|
||||
|
||||
for (const file of eventFiles) {
|
||||
const event = (await import(join(eventsPath, file))).default;
|
||||
client[event.data.once ? 'once' : 'on'](event.data.name, async (...args) => event.data.execute(...args));
|
||||
}
|
||||
|
||||
void client.login();
|
||||
1
packages/create-discord-bot/template/TypeScript/.env
Normal file
1
packages/create-discord-bot/template/TypeScript/.env
Normal file
@@ -0,0 +1 @@
|
||||
DISCORD_TOKEN=
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"root": true,
|
||||
"extends": ["neon/common", "neon/node", "neon/typescript", "neon/prettier"],
|
||||
"parserOptions": {
|
||||
"project": ["./tsconfig.eslint.json"]
|
||||
},
|
||||
"ignorePatterns": ["dist/*"]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"quoteProps": "as-needed",
|
||||
"trailingComma": "all",
|
||||
"endOfLine": "lf"
|
||||
}
|
||||
25
packages/create-discord-bot/template/TypeScript/package.json
Normal file
25
packages/create-discord-bot/template/TypeScript/package.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "[REPLACE-NAME]",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "tsc",
|
||||
"lint": "prettier --check . && eslint ./src --ext .ts --format=pretty",
|
||||
"format": "prettier --write . && eslint ./src --ext .ts --fix --format=pretty",
|
||||
"start": "node --require dotenv/config dist/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"discord.js": "^14.11.0",
|
||||
"dotenv": "^16.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sapphire/ts-config": "^4.0.0",
|
||||
"@types/node": "^18.15.3",
|
||||
"eslint": "^8.40.0",
|
||||
"eslint-config-neon": "^0.1.47",
|
||||
"eslint-formatter-pretty": "^5.0.0",
|
||||
"prettier": "^2.8.8",
|
||||
"typescript": "^5.0.4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import type { ClientEvents } from 'discord.js';
|
||||
|
||||
export interface Event<T extends keyof ClientEvents = keyof ClientEvents> {
|
||||
execute(...parameters: ClientEvents[T]): Promise<void> | void;
|
||||
name: T;
|
||||
once?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Events } from 'discord.js';
|
||||
import type { Event } from './index.js';
|
||||
|
||||
export default {
|
||||
name: Events.ClientReady,
|
||||
once: true,
|
||||
async execute(client) {
|
||||
console.log(`Ready! Logged in as ${client.user.tag}`);
|
||||
},
|
||||
} satisfies Event<'ready'>;
|
||||
19
packages/create-discord-bot/template/TypeScript/src/index.ts
Normal file
19
packages/create-discord-bot/template/TypeScript/src/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { readdir } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath, URL } from 'node:url';
|
||||
import { Client, GatewayIntentBits } from 'discord.js';
|
||||
import type { Event } from './events/index.js';
|
||||
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
const eventsPath = fileURLToPath(new URL('events', import.meta.url));
|
||||
|
||||
const eventFiles = await readdir(eventsPath).then((files) =>
|
||||
files.filter((file) => file.endsWith('.js') && file !== 'index.js'),
|
||||
);
|
||||
|
||||
for (const file of eventFiles) {
|
||||
const event: Event = (await import(join(eventsPath, file))).default;
|
||||
client[event.once ? 'once' : 'on'](event.name, async (...args) => event.execute(...args));
|
||||
}
|
||||
|
||||
void client.login();
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"allowJs": true
|
||||
},
|
||||
"include": ["**/*.ts", "**/*.js", "**/*.test.ts", "**/*.test.js"],
|
||||
"exclude": []
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"extends": "@sapphire/ts-config/extra-strict",
|
||||
"compilerOptions": {
|
||||
"declaration": false,
|
||||
"declarationMap": false,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"target": "ESNext",
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user