Skip to content

Commit

Permalink
feat(commands): remove json config
Browse files Browse the repository at this point in the history
  • Loading branch information
dan5py committed Jan 9, 2024
1 parent bff4e1c commit 7849ca5
Show file tree
Hide file tree
Showing 16 changed files with 1,023 additions and 911 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ISC License

Copyright (c) [year] [fullname]
Copyright (c) [2024] [dan5py]

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
Expand Down
81 changes: 55 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,74 @@
# DiscordJS Bot Template

> Updated to discord.js v14.11.0
> Updated to discord.js v14.14.1
## About

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.

## Setup

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

## Usage

### Add Slash commands

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

The command will be automatically registered when the bot starts.

### Events
### Creating a command file

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.
You can create a new command using `TypeScript`.

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

See the [DiscordJS documentation](https://old.discordjs.dev/#/docs/discord.js/main/typedef/Events) for a list of events.
```ts
import { SlashCommand, SlashCommandConfig } from '@/types/command';

const config: SlashCommandConfig = {
...
};

const command: SlashCommand = {
...
};

export default { command, config };
```

> [!NOTE]
> You can see all the types definition in `src/types/command.ts`.
### Commands JSON file
#### SlashCommandConfig

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

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).
| Property | Type | Required | Description |
| ----------- | ---------------- | -------- | --------------------------------------------------------------------- |
| name | `string` | No | The name of the command. If not defined, the filename is used instead |
| description | `string` | Yes | The description of the command. |
| usage | `string` | No | The usage of the command. |
| category | `string` | No | The category of the command. |
| nsfw | `boolean` | No | Whether this command is NSFW or not (Default: false). |
| options | `Array<Options>` | No | The list of options for this command. (see [](/#options)) |

### Properties
> [!IMPORTANT]
> The `fileName` property is automatically added to the config object, DO NOT add it manually.
| Property | Type | Required | Description |
| ----------- | ---------------- | -------- | ------------------------------------------------------ |
| name | `string` | Yes | The name of the command. |
| description | `string` | Yes | The description of the command. |
| usage | `string` | No | The usage of the command. |
| category | `string` | No | The category of the command (matches the folder path). |
| nsfw | `boolean` | No | Whether this command is NSFW or not (Default: false). |
| options | `Array<Options>` | No | The list of options for this command. |
#### SlashCommand

The `command` object contains the function that will be executed when the command is called.
It also contains the `permissions` for the command. (see [Permissions Guide](https://discordjs.guide/popular-topics/permissions.html#permissions))

#### Options

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

### Events

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.

| Event Source | Description |
| ------------ | --------------------------------------------- |
| `client` | Events emitted by the client (e.g. ready) |
| `guild` | Events emitted by a guild (e.g. interactions) |

See the [DiscordJS documentation](https://old.discordjs.dev/#/docs/discord.js/main/typedef/Events) for a list of events.

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Expand Down
28 changes: 0 additions & 28 deletions config/slashCommands.json

This file was deleted.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "discordjs-template-ts",
"description": "A template for discord.js with TypeScript",
"version": "14.11.0-0.1.2",
"version": "14.14.1-0.1.3",
"license": "ISC",
"main": "dist/src/index.js",
"scripts": {
Expand All @@ -11,19 +11,24 @@
},
"dependencies": {
"chalk": "4.1.2",
"discord.js": "^14.11.0",
"discord.js": "^14.14.1",
"dotenv": "^16.0.3",
"fs-extra": "^11.2.0",
"module-alias": "^2.2.2"
},
"_moduleAliases": {
"@": "dist/src",
"@config": "dist/src/config"
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.2.5",
"cross-env": "^7.0.3",
"nodemon": "^2.0.22",
"nodemon": "^3.0.2",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.6",
"typescript": "^5.0.4"
"tsconfig-paths": "^4.2.0",
"tslib": "^2.6.2",
"typescript": "^5.3.3"
}
}
Loading

0 comments on commit 7849ca5

Please sign in to comment.