- Music: Play and manage music in your Discord server using Erela.js with Spotify integration.
- Moderation: Tools for server moderation.
- Information Commands: Access various information commands, including FFXIV Lodestone character data.
- Logging: Centralized logging system using Consola for better debugging and monitoring.
- Error Handling: Robust error handling using Effect.
- Hot Reloading: Automatic reloading of commands and events during development.
Terra is a Discord bot written in TypeScript using the Eris library for Discord bot functionality. It features a modular command system, event handling, and integration with external APIs like FFXIV Lodestone.
- Server: Node.js, Bun, Eris
- Music: Erela.js with Spotify integration
- Logging: Consola
- Error Handling: Effect
- File Scanning: Globby
- Hot Reloading: Chokidar, perfect-debounce
-
Install Bun:
For macOS and Linux:
curl -fsSL https://bun.sh/install | bash
For Windows:
powershell -c "irm bun.sh/install.ps1|iex"
Note: Bun requires a minimum of Windows 10 version 1809.
-
Verify the installation:
bun --version
-
Clone the repository:
git clone https://github.com/pieckenst/terra.git cd terra
-
Install dependencies:
bun install
-
Set up your environment variables in a .env file:
token=YOUR_DISCORD_BOT_TOKEN
-
Create a config.json file in the root directory with the following structure:
{
"prefix": "!",
"dirs": {
"commands": "./commands",
"events": "./events"
},
"debug": true,
"clientID": "YOUR_SPOTIFY_CLIENT_ID",
"clientSecret": "YOUR_SPOTIFY_CLIENT_SECRET",
"host": "localhost",
"port": 2333,
"password": "youshallnotpass",
"ownerId": "YOUR_DISCORD_USER_ID"
}
We recommend using bun package manager to launch this TypeScript project. To start the bot, run:
bun run core.ts
Command examples:
!lodestone Cerberus Zenos yae Galvus
: This command fetches FFXIV character information from Lodestone..!ban [user]
: Bans a user from the server.
The core file initializes the bot and sets up command and event handling:
async function main() {
const harmonix = await initHarmonix();
await loadCommands(harmonix);
await loadEvents(harmonix);
// ... (event listeners and error handling)
}
Terra uses a flexible command structure defined in discordkit/utils/command.ts. The command.ts file in the Terra project provides a robust and flexible structure for defining commands, which is essential for several reasons:
Slash Command Support: Regular Eris has limited support for slash commands. By using the command.ts structure, Terra seamlessly integrates slash command functionality, allowing developers to create both traditional and slash commands with ease.
Cleaner and More Readable Structure: The class-based approach with static members offers a clear and organized way to define commands. It separates configuration from execution logic, making the code more maintainable and easier to understand at a glance.
Consistent Error Handling: The command structure incorporates built-in error handling, ensuring that all commands have a standardized way of dealing with exceptions. This consistency improves the overall reliability of the bot.
Type Safety: By leveraging TypeScript's type system, the command structure provides better type checking and autocompletion, reducing the likelihood of runtime errors.
Extensibility: The class-based approach allows for easy extension and modification of command behavior through inheritance if needed.
Precondition and Permission Handling: The structure includes built-in support for command permissions and owner-only restrictions, simplifying the implementation of access control.
Unified Interface: By using a consistent structure for all commands, it becomes easier to implement features like command help generation or command management systems.
Hot Reloading Support: The structure is designed to work well with hot reloading, facilitating easier development and testing of commands.
Using this command structure results in a more stable, maintainable, and feature-rich codebase for Terra, addressing the limitations of vanilla TypeScript structures when working with Eris and slash commands. Here's how to create a command:
import { defineCommand } from '../../discordkit/utils/command';
export default class extends defineCommand({
name: "commandname",
description: "Command description",
usage: "commandname <arg>",
category: "Category",
aliases: [],
slashCommand: true,
options: [], // For slash command options
permissions: ['SEND_MESSAGES'],
ownerOnly: false,
}) {
static async execute(harmonix, message, args) {
// Command logic here
}
}
This structure allows for easy creation of both regular and slash commands, with built-in permission checks and owner-only restrictions.
We welcome contributions! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or fix.
- Submit a pull request describing your changes.
To run this project, you will need to add the following environment variables to your .env file
token
- Your Discord bot token
If you have any feedback, please reach out in the discord server https://discord.com/invite/XjKfPTa5Kq