Skip to content

Commit b659ce5

Browse files
committed
🎉 First release
1 parent 8022adb commit b659ce5

File tree

21 files changed

+1506
-0
lines changed

21 files changed

+1506
-0
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DISCORD_TOKEN=your_token
2+
DISCORD_APP_ID=your_app_id

.gitignore

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
### Node ###
2+
# Logs
3+
logs
4+
*.log
5+
npm-debug.log*
6+
yarn-debug.log*
7+
yarn-error.log*
8+
lerna-debug.log*
9+
.pnpm-debug.log*
10+
11+
# Runtime data
12+
pids
13+
*.pid
14+
*.seed
15+
*.pid.lock
16+
17+
# Dependency directories
18+
node_modules/
19+
20+
# TypeScript cache
21+
*.tsbuildinfo
22+
23+
# Optional npm cache directory
24+
.npm
25+
26+
# Yarn Integrity file
27+
.yarn-integrity
28+
29+
# dotenv environment variable files
30+
.env
31+
.env.development.local
32+
.env.test.local
33+
.env.production.local
34+
.env.local
35+
36+
# build
37+
dist/

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"json.schemas": [
3+
{
4+
"fileMatch": ["config/slashCommands.json"],
5+
"url": "./schemas/slash-commands.json"
6+
}
7+
]
8+
}

LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ISC License
2+
3+
Copyright (c) [year] [fullname]
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15+
PERFORMANCE OF THIS SOFTWARE.

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,100 @@
11
# DiscordJS Bot Template
2+
3+
> Updated to discord.js v14.11.0
4+
5+
## About
6+
7+
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.
8+
9+
## Setup
10+
11+
1. Clone the repository
12+
2. Run `yarn` to install dependencies
13+
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+
18+
## Usage
19+
20+
### Add Slash commands
21+
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)
24+
25+
The command will be automatically registered when the bot starts.
26+
27+
### Events
28+
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.
30+
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) |
35+
36+
See the [DiscordJS documentation](https://old.discordjs.dev/#/docs/discord.js/main/typedef/Events) for a list of events.
37+
38+
### Commands JSON file
39+
40+
The `config/slashCommands.json` file is used to configure the active slash commands.
41+
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).
43+
44+
### Properties
45+
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. |
54+
55+
#### Options
56+
57+
The list of options for this command.
58+
59+
| Property | Type | Required | Description | Valid in Types |
60+
| ----------- | ---------------- | -------- | --------------------------------------------------------- | ----------------------------- |
61+
| name | `string` | Yes | The name of the option. | All |
62+
| description | `string` | Yes | The description of the option. | All |
63+
| type | `string` | Yes | The type of the option. See [Option Types](#option-types) | All |
64+
| required | `boolean` | No | Whether this option is required or not (Default: false). | All |
65+
| choices | `Array<Choices>` | No | The list of choices for this option. | `INTEGER \| NUMBER \| STRING` |
66+
| minValue | `number` | No | The minimum value of the option. | `INTEGER \| NUMBER` |
67+
| maxValue | `number` | No | The maximum value of the option. | `INTEGER \| NUMBER` |
68+
69+
##### Choice Properties
70+
71+
The properties of each choice within the `choices` array.
72+
73+
| Property | Type | Description |
74+
| -------- | ------------------ | ----------------------------------------------------------------------------------- |
75+
| name | `string` | The name of the choice. |
76+
| value | `string \| number` | The value of the choice (the available value is based on the off the option value). |
77+
78+
#### Option Types
79+
80+
For further information on option types, see the [Discord documentation](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-type).
81+
82+
| Type | Description |
83+
| ------------- | -------------------------------- |
84+
| `STRING` | Represents a string value. |
85+
| `BOOLEAN` | Represents a boolean value. |
86+
| `NUMBER` | Represents a numeric value. |
87+
| `INTEGER` | Represents an integer value. |
88+
| `ROLE` | Represents a role. |
89+
| `USER` | Represents a user. |
90+
| `CHANNEL` | Represents a channel. |
91+
| `MENTIONABLE` | Represents a mentionable entity. |
92+
| `ATTACHMENT` | Represents an attachment. |
93+
94+
## Contributing
95+
96+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
97+
98+
## License
99+
100+
[ISC](https://choosealicense.com/licenses/isc/)

config/slashCommands.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[
2+
{
3+
"name": "ping",
4+
"description": "Show the latency of the bot",
5+
"options": [
6+
{
7+
"name": "emoji",
8+
"description": "Give me an emoji",
9+
"type": "STRING",
10+
"choices": [
11+
{
12+
"name": "🏓",
13+
"value": "🏓"
14+
},
15+
{
16+
"name": "👍",
17+
"value": "👍"
18+
},
19+
{
20+
"name": "👎",
21+
"value": "👎"
22+
}
23+
],
24+
"required": false
25+
}
26+
]
27+
}
28+
]

env.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace NodeJS {
2+
interface ProcessEnv {
3+
DISCORD_TOKEN: string | undefined;
4+
DISCORD_APP_ID: string | undefined;
5+
}
6+
}

nodemon.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"watch": ["src"],
3+
"ext": "ts,json",
4+
"ignore": ["src/**/*.spec.ts"],
5+
"exec": "ts-node -r tsconfig-paths/register ./src/index.ts"
6+
}

package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "discordjs-template-ts",
3+
"description": "A template for discord.js with TypeScript",
4+
"version": "14.11.0-0.1.0",
5+
"license": "ISC",
6+
"main": "dist/src/index.js",
7+
"scripts": {
8+
"dev": "nodemon",
9+
"build": "tsc && tsc-alias",
10+
"start": "node ./dist/src/index.js"
11+
},
12+
"dependencies": {
13+
"chalk": "4.1.2",
14+
"discord.js": "^14.11.0",
15+
"dotenv": "^16.0.3",
16+
"module-alias": "^2.2.2"
17+
},
18+
"_moduleAliases": {
19+
"@": "dist/src",
20+
"@config": "dist/src/config"
21+
},
22+
"devDependencies": {
23+
"@types/node": "^20.2.5",
24+
"nodemon": "^2.0.22",
25+
"tsc-alias": "^1.8.6",
26+
"typescript": "^5.0.4"
27+
}
28+
}

schemas/slash-commands.json

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"type": "array",
4+
"description": "The list of available slash commands",
5+
"items": {
6+
"type": "object",
7+
"properties": {
8+
"name": {
9+
"type": "string",
10+
"description": "The name of the command"
11+
},
12+
"description": {
13+
"type": "string",
14+
"description": "The description of the command"
15+
},
16+
"usage": {
17+
"type": "string",
18+
"description": "The usage of the command"
19+
},
20+
"category": {
21+
"type": "string",
22+
"description": "The category of the command (matches the folder path, e.g. `general/info`)"
23+
},
24+
"nsfw": {
25+
"type": "boolean",
26+
"description": "Whether this command is NSFW or not",
27+
"default": false
28+
},
29+
"options": {
30+
"type": "array",
31+
"description": "The list of options for this command",
32+
"items": {
33+
"type": "object",
34+
"description": "An option for a command",
35+
"properties": {
36+
"name": {
37+
"type": "string",
38+
"description": "The name of the option"
39+
},
40+
"description": {
41+
"type": "string",
42+
"description": "The description of the option"
43+
},
44+
"type": {
45+
"enum": [
46+
"STRING",
47+
"BOOLEAN",
48+
"NUMBER",
49+
"INTEGER",
50+
"ROLE",
51+
"USER",
52+
"CHANNEL",
53+
"MENTIONABLE",
54+
"ATTACHMENT"
55+
],
56+
"description": "The type of the option"
57+
},
58+
"required": {
59+
"type": "boolean",
60+
"description": "Whether this option is required or not",
61+
"default": false
62+
},
63+
"choices": {
64+
"type": "array",
65+
"items": {
66+
"type": "object",
67+
"properties": {
68+
"name": {
69+
"type": "string",
70+
"description": "The name of the choice"
71+
},
72+
"value": {
73+
"type": ["string", "number"],
74+
"description": "The value of the choice"
75+
}
76+
}
77+
},
78+
"description": "The list of choices for this option (INTEGER)"
79+
},
80+
"minValue": {
81+
"type": "number",
82+
"description": "The minimum value of the option (INTEGER, NUMBER)"
83+
},
84+
"maxValue": {
85+
"type": "number",
86+
"description": "The maximum value of the option (INTEGER, NUMBER)"
87+
}
88+
},
89+
"required": ["name", "description", "type"]
90+
}
91+
}
92+
},
93+
"required": ["name", "description"]
94+
}
95+
}

0 commit comments

Comments
 (0)