Skip to content

Commit 7849ca5

Browse files
committed
feat(commands): remove json config
1 parent bff4e1c commit 7849ca5

File tree

16 files changed

+1023
-911
lines changed

16 files changed

+1023
-911
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ISC License
22

3-
Copyright (c) [year] [fullname]
3+
Copyright (c) [2024] [dan5py]
44

55
Permission to use, copy, modify, and/or distribute this software for any
66
purpose with or without fee is hereby granted, provided that the above

README.md

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,74 @@
11
# DiscordJS Bot Template
22

3-
> Updated to discord.js v14.11.0
3+
> Updated to discord.js v14.14.1
44
55
## About
66

77
This is a template for a DiscordJS v14 bot. It is written in TypeScript and uses [DiscordJS](https://discord.js.org/#/) as the library for interacting with Discord.
88

99
## Setup
1010

11+
> **Note**
12+
> This project uses [pnpm](https://pnpm.io/) as the package manager. You can use `npm` or `yarn` if you prefer.
13+
1114
1. Clone the repository
12-
2. Run `yarn` to install dependencies
15+
2. Run `pnpm i` to install dependencies
1316
3. Copy `.env.example` to `.env` and fill in the values
14-
4. Run `yarn dev` to start the bot in development mode
15-
5. Run `yarn build` to build the bot
16-
6. Run `yarn start` to start the bot in production mode
17+
4. Run `pnpm dev` to start the bot in development mode
18+
5. Run `pnpm build` to build the bot
19+
6. Run `pnpm start` to start the bot in production mode
1720

1821
## Usage
1922

2023
### Add Slash commands
2124

22-
1. Add your command in `config/slashCommands.json`
23-
2. Create a file in `src/commands/slash` with the same name as the command (in the relative subfolder if in a category)
25+
1. Create a `.ts` file in `src/commands/slash` with the same name as the command (in the relative subfolder if in a category)
2426

2527
The command will be automatically registered when the bot starts.
2628

27-
### Events
29+
### Creating a command file
2830

29-
Events are automatically registered when the bot starts. To add an event, create a file in `src/events/<event_source>` with the name of the event and export default the event function.
31+
You can create a new command using `TypeScript`.
3032

31-
| Event Source | Description |
32-
| ------------ | --------------------------------------------- |
33-
| `client` | Events emitted by the client (e.g. ready) |
34-
| `guild` | Events emitted by a guild (e.g. interactions) |
33+
The file must export the following object:
3534

36-
See the [DiscordJS documentation](https://old.discordjs.dev/#/docs/discord.js/main/typedef/Events) for a list of events.
35+
```ts
36+
import { SlashCommand, SlashCommandConfig } from '@/types/command';
37+
38+
const config: SlashCommandConfig = {
39+
...
40+
};
41+
42+
const command: SlashCommand = {
43+
...
44+
};
45+
46+
export default { command, config };
47+
```
48+
49+
> [!NOTE]
50+
> You can see all the types definition in `src/types/command.ts`.
3751
38-
### Commands JSON file
52+
#### SlashCommandConfig
3953

40-
The `config/slashCommands.json` file is used to configure the active slash commands.
54+
The `config` of the command contains all the information about the command that will be loaded.
4155

42-
Is based of the schema `schemas/slash-commands.json` so you can use it to validate your JSON file (in VSCode the schema is automatically loaded).
56+
| Property | Type | Required | Description |
57+
| ----------- | ---------------- | -------- | --------------------------------------------------------------------- |
58+
| name | `string` | No | The name of the command. If not defined, the filename is used instead |
59+
| description | `string` | Yes | The description of the command. |
60+
| usage | `string` | No | The usage of the command. |
61+
| category | `string` | No | The category of the command. |
62+
| nsfw | `boolean` | No | Whether this command is NSFW or not (Default: false). |
63+
| options | `Array<Options>` | No | The list of options for this command. (see [](/#options)) |
4364

44-
### Properties
65+
> [!IMPORTANT]
66+
> The `fileName` property is automatically added to the config object, DO NOT add it manually.
4567
46-
| Property | Type | Required | Description |
47-
| ----------- | ---------------- | -------- | ------------------------------------------------------ |
48-
| name | `string` | Yes | The name of the command. |
49-
| description | `string` | Yes | The description of the command. |
50-
| usage | `string` | No | The usage of the command. |
51-
| category | `string` | No | The category of the command (matches the folder path). |
52-
| nsfw | `boolean` | No | Whether this command is NSFW or not (Default: false). |
53-
| options | `Array<Options>` | No | The list of options for this command. |
68+
#### SlashCommand
69+
70+
The `command` object contains the function that will be executed when the command is called.
71+
It also contains the `permissions` for the command. (see [Permissions Guide](https://discordjs.guide/popular-topics/permissions.html#permissions))
5472

5573
#### Options
5674

@@ -91,6 +109,17 @@ For further information on option types, see the [Discord documentation](https:/
91109
| `MENTIONABLE` | Represents a mentionable entity. |
92110
| `ATTACHMENT` | Represents an attachment. |
93111

112+
### Events
113+
114+
Events are automatically registered when the bot starts. To add an event, create a file in `src/events/<event_source>` with the name of the event and export default the event function.
115+
116+
| Event Source | Description |
117+
| ------------ | --------------------------------------------- |
118+
| `client` | Events emitted by the client (e.g. ready) |
119+
| `guild` | Events emitted by a guild (e.g. interactions) |
120+
121+
See the [DiscordJS documentation](https://old.discordjs.dev/#/docs/discord.js/main/typedef/Events) for a list of events.
122+
94123
## Contributing
95124

96125
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

config/slashCommands.json

Lines changed: 0 additions & 28 deletions
This file was deleted.

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "discordjs-template-ts",
33
"description": "A template for discord.js with TypeScript",
4-
"version": "14.11.0-0.1.2",
4+
"version": "14.14.1-0.1.3",
55
"license": "ISC",
66
"main": "dist/src/index.js",
77
"scripts": {
@@ -11,19 +11,24 @@
1111
},
1212
"dependencies": {
1313
"chalk": "4.1.2",
14-
"discord.js": "^14.11.0",
14+
"discord.js": "^14.14.1",
1515
"dotenv": "^16.0.3",
16+
"fs-extra": "^11.2.0",
1617
"module-alias": "^2.2.2"
1718
},
1819
"_moduleAliases": {
1920
"@": "dist/src",
2021
"@config": "dist/src/config"
2122
},
2223
"devDependencies": {
24+
"@types/fs-extra": "^11.0.4",
2325
"@types/node": "^20.2.5",
2426
"cross-env": "^7.0.3",
25-
"nodemon": "^2.0.22",
27+
"nodemon": "^3.0.2",
28+
"ts-node": "^10.9.2",
2629
"tsc-alias": "^1.8.6",
27-
"typescript": "^5.0.4"
30+
"tsconfig-paths": "^4.2.0",
31+
"tslib": "^2.6.2",
32+
"typescript": "^5.3.3"
2833
}
2934
}

0 commit comments

Comments
 (0)