A Discord bot for the Patches Santai GG community, built with discord.js v14.16.3
The official Discord bot from SantaiGG.
- Clone the repository
- Install Bun if you haven't already
Note: Bun is recommended over npm/yarn for this project but you can also use npm/yarn/pnpm
- Run
bun install
to install dependencies - Copy
.env.example
to.env
and fill in the values - Run
bun dev
to start the bot in development mode - Run
bun build
to build the bot - Run
bun start
to start the bot in production mode
- Create a
.ts
file insrc/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.
Commands are created using TypeScript. Each command file must export the following object:
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
.
The config
of the command contains all the information about the command that will be loaded.
Important
The fileName
property is automatically added to the config object, DO NOT add it manually.
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)
The list of options for this command.
Property | Type | Required | Description | Valid in Types |
---|---|---|---|---|
name | string |
Yes | The name of the option. | All |
description | string |
Yes | The description of the option. | All |
type | string |
Yes | The type of the option. See Option Types | All |
required | boolean |
No | Whether this option is required or not (Default: false). | All |
choices | Array<Choices> |
No | The list of choices for this option. | INTEGER | NUMBER | STRING |
minValue | number |
No | The minimum value of the option. | INTEGER | NUMBER |
maxValue | number |
No | The maximum value of the option. | INTEGER | NUMBER |
The properties of each choice within the choices
array.
Property | Type | Description |
---|---|---|
name | string |
The name of the choice. |
value | string | number |
The value of the choice (the available value is based on the off the option value). |
For further information on option types, see the Discord documentation.
Type | Description |
---|---|
STRING |
Represents a string value. |
BOOLEAN |
Represents a boolean value. |
NUMBER |
Represents a numeric value. |
INTEGER |
Represents an integer value. |
ROLE |
Represents a role. |
USER |
Represents a user. |
CHANNEL |
Represents a channel. |
MENTIONABLE |
Represents a mentionable entity. |
ATTACHMENT |
Represents an attachment. |
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 for a list of events.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
If you prefer using NPM, Yarn, or PNPM, you'll need to make a few adjustments since this project is optimized for Bun:
Important
These changes are for local development only. Please don't commit changes to package.json that remove Bun support.
- Install additional dependencies:
# Using npm
npm install -D tsx tsup nodemon cross-env dotenv
# Using yarn
yarn add -D tsx tsup nodemon cross-env dotenv
# Using pnpm
pnpm add -D tsx tsup nodemon cross-env dotenv
- Temporarily modify your
package.json
scripts (but don't commit these changes):
{
"scripts": {
"dev": "nodemon",
"build": "tsup",
"start": "cross-env NODE_ENV=production node dist/index.js",
"format": "prettier --write ."
}
}
- Create a
nodemon.json
file in the root directory:
{
"watch": ["src"],
"ext": ".ts,.js",
"ignore": [],
"exec": "tsx src/index.ts"
}
- Create a
tsup.config.ts
file in the root directory:
import { defineConfig } from 'tsup';
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm'],
clean: true,
minify: true,
target: 'node18',
});
- Add
dotenv.config()
to the top of yoursrc/index.ts
file:
import 'dotenv/config';
// ... rest of your code
Now you can use the equivalent commands:
npm run dev
/yarn dev
/pnpm dev
npm run build
/yarn build
/pnpm build
npm run start
/yarn start
/pnpm start
Note
While these alternative setups will work, we recommend using Bun for the best development experience with this project.