Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/proxitystudios/discord-bot-starter-js
https://github.com/proxitystudios/discord-bot-starter-js
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/proxitystudios/discord-bot-starter-js
- Owner: ProxityStudios
- Created: 2024-02-06T17:10:24.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-02-06T17:45:43.000Z (11 months ago)
- Last Synced: 2024-02-06T18:30:45.660Z (11 months ago)
- Language: JavaScript
- Size: 53.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Discord Bot Starter TS
This is a TypeScript template for creating Discord bots using the [discord.js](https://discord.js.org/) library. It provides a basic structure and some useful features to help you get started quickly and easily.
## How to use
1. Clone or download this repository
2. Run `npm install` to install the required packages
3. Rename `.env.example` to `.env` and fill out everything
4. Run `npm run dev` to start the bot in development mode
5. Write your bot logic in the `src` folder## Scripts
### Development mode
```bash
npm run dev
```Starts the bot using `ts-node-dev`, which auto-restarts on code changes.
### Production mode
```bash
npm start
```Compiles TypeScript to JavaScript and starts the bot using `ts-node`.
## Features
### Command handler
A flexible and modular way to create and manage commands for your bot. You can add new commands by creating a file in the `src/commands` folder that follows this structure:
```typescript
export default class extends Command {
public constructor(client: CustomClient) {
super(client, {
// The name of the command
name: CommandName.Example,
// A brief description of what the command does
description: "This is an example description.",
// The category of the command
category: CommandCategory.General,
});
}public async execute(
interaction: ChatInputCommandInteraction
): Promise {
// Command logic goes here
await interaction.reply({
content: `This is an example answer.`,
});
}
}
```You can also organize your commands into subfolders based on their categories. For example, you can create a file in `src/commands/moderation/ban.ts` for a ban command. However, you will need to add the new command name and category to the `types.ts` file as well. For example:
```typescript
export enum CommandName {
// ...
// Moderation
Ban = "ban",
}export enum CommandCategory {
// ...
Moderation = "Moderation",
}
```### Slash commands
You can create slash command options by using `this.data` property. For example, this is how you can add a `String` option:
```typescript
super(client, {
// ...
});// Creating slash command options
this.data.addStringOption((option) =>
option
.setName("input")
.setDescription("The input to echo back")
.setRequired(true)
);
```To use the options, you need to access them from the `interaction.options` property. For example, this is how you can get the value of the `String` option in your execute method:
```typescript
public async execute(
interaction: ChatInputCommandInteraction
): Promise {
// The logic of the slash command goes here
const input = interaction.options.getString("input");
await interaction.reply({
content: `You said: ${input}`,
});
}
```