Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c7b52b3
updated pakages
bowenjw May 20, 2023
7637026
updated configs
bowenjw May 20, 2023
4180e24
Updates i18n system
bowenjw May 20, 2023
45d7b7a
remove old globle
bowenjw May 20, 2023
d9a9596
Update to client structuses
bowenjw May 20, 2023
55ce5e5
Merge pull request #4 from bowenjw/Core-update
bowenjw May 20, 2023
fe1e1be
Create readme.md
bowenjw May 20, 2023
ba2aae7
removed deployment from ready
bowenjw May 20, 2023
a149a7d
eslint fix
bowenjw May 20, 2023
fee3b35
add vscode config and code fixes
bowenjw Jun 8, 2023
b113f5f
added guild command support
bowenjw Jun 11, 2023
16bac0f
added shard manager
bowenjw Jun 11, 2023
d3a5728
client update update
bowenjw Feb 3, 2024
d995cb8
handler and i18n rewrite
bowenjw Feb 4, 2024
704f987
eslint update
bowenjw Feb 4, 2024
ea14ad1
bug fix
bowenjw Feb 4, 2024
71c191d
bug fix
bowenjw Feb 9, 2024
848b274
refactor all commands
bowenjw Feb 19, 2024
7242d09
updateded pakages
bowenjw Mar 2, 2024
e40893e
refactor files
bowenjw Mar 2, 2024
0da3397
remove some parts of the read me
bowenjw Mar 2, 2024
07713f2
update to nodenext
bowenjw Apr 16, 2024
4c984e4
bug fix
bowenjw Apr 16, 2024
718c42b
more bug fixes
bowenjw Apr 16, 2024
fc617af
bug fix
bowenjw Apr 16, 2024
dd97ffe
format fixes
bowenjw Apr 16, 2024
a44d341
bug fix
bowenjw Apr 16, 2024
0e4c643
added comment
bowenjw Apr 16, 2024
0b42669
changed version
bowenjw Apr 16, 2024
5bb9f78
bug fixes
bowenjw Apr 16, 2024
f0abda8
updated readme
bowenjw Apr 16, 2024
2c9325a
package lock update
bowenjw Apr 16, 2024
cc21361
Merge branch 'main' into pr/bowenjw/16
bowenjw Apr 16, 2024
d09fd52
added french locale
bowenjw Apr 16, 2024
0cfd799
bug fix
bowenjw Apr 16, 2024
64ef7d1
bug fix
bowenjw Apr 24, 2024
ffc09b6
added readmes
bowenjw Apr 24, 2024
8154dbe
added new events
bowenjw Apr 24, 2024
fd03004
typo fixed
bowenjw Apr 24, 2024
e6a4c8e
style fixes
bowenjw Apr 25, 2024
fb42daf
Added missing type to chatcommand
bowenjw May 17, 2024
ed712b2
new packages
bowenjw Sep 19, 2024
cfece1b
spelling fixes
bowenjw Sep 20, 2024
d7b9bce
moved object in to main
bowenjw Sep 20, 2024
0b9cb3a
spelling fixes
bowenjw Sep 20, 2024
d330ddc
bug fix
bowenjw Sep 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions .eslintrc.json

This file was deleted.

1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=CRLF
11 changes: 11 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"ms-vscode.vscode-typescript-next",
"christian-kohler.path-intellisense",
"macabeus.vscode-fluent",
"visualstudioexptteam.vscodeintellicode",
"visualstudioexptteam.intellicode-api-usage-examples",
"christian-kohler.npm-intellisense"
]
}
20 changes: 20 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"files.eol": "\r\n",
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.detectIndentation": false,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"eslint.useFlatConfig": true,
"eslint.workingDirectories": [
{
"mode": "auto"
}
],
"cSpell.words": [
"GUILDID",
"repliable"
]
}
102 changes: 45 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,89 +14,76 @@
A multi-purpose discord.js v14 bot template.
This is the successor of the [djs-template](https://github.com/ppauel/djs-template) repository.

This template is still 🚧 under development 🚧 and will be constantly extended, for example when changes are made to the Discord API.

## Features

- Slash Command Handler (global / guild)
- Context Menu Handler (global / guild)
- Command Handler (global / guild)
- Interaction Handler (Message Components, Modals)
- Event Handler
- Sharding
- Localizations
- Customizable configuration
- [Examples](#demo-files)

## Installation

Install the required `npm` modules.
Intsall Node.js 20.6.0 or later. The latest version of Node.js can be installed from [here](https://nodejs.org/en/download/current)

Cone the repo then install the required `npm` modules.

```bash
git clone https://github.com/ppauel/typescript-discord-bot.git new_bot
npm install
```
In the root of the project create a copy of `example.env` then rename it to `.env` this file contains all environmental variables for the project. replace the `TOKEN` with your Application's [Bot Token](https://discord.com/developers/docs/quick-start/getting-started#configuring-your-bot).

Create a new file called `.env` in the root directory and insert your bot token as shown in the `example.env` file.
**Optional:** Replace `GUILDID` if you wish to deploy commands to a Spific guild

### Configuration
Apart from the token, the configuration takes place in the `config.json` file located in the `src/` folder.

Specify a **guild ID** to which the guild commands will be deployed. Make sure that the bot is a member of this server and has sufficient permissions to create commands.
```json
"guild": "your_guild_id"
The `.env` only contains information which you may want to keep private like your bots token.
To configure the bot is done in `src/bot.ts` with the client options. Extended from the [discord.js ClientOptions](https://old.discordjs.dev/#/docs/discord.js/14.14.1/typedef/ClientOptions).

Choose witch thyes of interaction you want your bot to interact with
- **[message components](https://discord.com/developers/docs/interactions/overview#message-components)** - buttons and select menus.
- **[modals](https://discord.com/developers/docs/interactions/overview#message-components)** - Pop up windows for text entry
- **[Autocomplete](https://discord.com/developers/docs/interactions/application-commands#autocomplete)** - Aoto complete options in slash commands
```typescript
receiveMessageComponents: true,
receiveModals: true,
receiveAutocomplete: true
```

Choose if you want to receive **message components** and **modals** using the interaction handler.
```json
"receiveMessageComponents": true,
"receiveModals": true
```
Select whether to reply with a meassage if an error occurs whilst executing an interaction.

Select whether to reply with a warning if an error occurs whilst executing an interaction.

```json
"replyOnError": true
Optional: You may provided a customised message
```typescript
replyOnError: true,
replyMessageOnError: "Error message here"
```

Choose whether you want to split the custom ID of an interaction by **underscores** (_). In this case, the interaction handler uses only the string **before the first underscore** (if any).
This system makes sense if you want to use the custom ID to convey additional information.
When using interactions you may wish to included information in the custom ID of an interaction.

For example `report_527814442746904591` is treated as `report`.
```json
"splitCustomId": false

By adding this option the interaction hadaler will parse custom IDs using the charicter
```typescript
splitCustomIDOn: "_"
```

If you want to use global commands only, you can disable guild commands. The `global` attribute must still be `true`.
```json
"useGuildCommands": true
Optional: if you would like to write your own `onInteractionCreate` event handling set this option to `false`.
```typescript
useDefaultInterctionEvent: true
```

**Done!** You can now experiment with some examples. For that, you just need to start your bot...
## Scripts

The bot can be started as a single instance or in processes intended for sharding. For smaller bots, the first variant should be sufficient.

To build & start the bot without sharding run
## Scripts

```bash
npm run start:bot
```
or just
To run the bot use the following command. this will both build and then run the bot
```bash
npm run start
```

To build & start the sharding manager run

```bash
npm run start:manager
```

During development, it is a good idea not to deploy all commands every time you restart. You can use the following command to disable automatic deployment and run the uncompiled bot / manager.
```bash
npm run dev:bot
```
```bash
npm run dev:manager
```

To only compile a JavaScript build of your bot, run this command.
```bash
npm run build
Expand All @@ -105,7 +92,9 @@ npm run build
The finished build will be located in the `dist/` directory.

## Usage / Examples

### Demo files

This template contains some sample commands and interactions so you understand how to use it:

- `src/commands/example/ping.ts` *Ping Command*
Expand All @@ -116,18 +105,17 @@ This template contains some sample commands and interactions so you understand h

- `src/context_menus/example/displayAvatar.ts` *User Context Menu*

**Hint:** *Commands, Context Menus and Interactions have to be located in a subfolder.*
**Hint:** *Commands, Context Menus and Interactions can be located in a subfolder.*

### ExtendedClient class

To make it easier to access the client's config and collections, the template includes the `ExtendedClient` class. It allows to access these properties directly from the client without importing them.
```javascript
const client = new ExtendedClient();
const guildId = client.config.guild;
```
However, the `ExtendedClient` cannot be accessed through an API object such as message or an interaction. The included handlers pass the `_client` as its own parameter, so you don't have to worry about that.

```typescript
const client = new ExtendedClient({splitCustomIDOn: '_'});
const splitCustomID = client.splitCustomIDOn;
```
Note: `ExtendedClient` my not be accesable every where client is as it is not part of the discord.js package.
### Localizations
By default, this project supports translations. These are managed in the `lang/` folder. The configuration is located in `src/features/i18n.ts`. Examples of usage can be found in the demo files.

## About this template
This template is still under development and will be constantly extended, for example when changes are made to the Discord API.
By default, this project supports translations. These are managed in the `locales/` folder. The configuration is located in `src/classes/i18n`. Examples of usage can be found in the demo files.
Loading