build(docker): add Dockerfile, Docker Compose config, and update README
This commit is contained in:
parent
47de3823f3
commit
6daf1993d1
23
Dockerfile
Normal file
23
Dockerfile
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Use official Node.js LTS image
|
||||||
|
FROM node:18-alpine
|
||||||
|
|
||||||
|
# Create app directory
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Install build dependencies and copy manifest
|
||||||
|
RUN apk add --no-cache python3 make g++
|
||||||
|
|
||||||
|
COPY package.json pnpm-lock.yaml ./
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
RUN npm ci
|
||||||
|
|
||||||
|
# Copy source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Expose no ports (Discord bot)
|
||||||
|
# Define default environment variables (optional)
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
# Start the bot
|
||||||
|
CMD ["node", "src/index.js"]
|
||||||
68
README.md
68
README.md
@ -1,57 +1,69 @@
|
|||||||
# discord-music-bot
|
# discord-music-bot
|
||||||
|
|
||||||
Discord music bot template written in Rust using `serenity` and `lavalink-rs`.
|
Discord music bot template written in NodeJS using `discord.js` and `erela.js`, with Lavalink support.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Slash commands: `/ping`, `/join`, `/play`, `/leave`
|
- Slash commands: `/ping`, `/join`, `/play`, `/leave`
|
||||||
- LavaLink integration for audio playback
|
- Lavalink integration for audio playback
|
||||||
- Modular command handler structure
|
- Modular command handler structure
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
- Rust (stable toolchain)
|
|
||||||
|
- Node.js (>=14)
|
||||||
|
- pnpm or npm
|
||||||
- A Discord application with bot token
|
- A Discord application with bot token
|
||||||
- LavaLink server running (see [LavaLink](https://github.com/freyacodes/Lavalink))
|
- LavaLink server for audio streaming
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
1. Copy `.env.example` to `.env` and fill in your credentials:
|
1. Copy `.env.example` to `.env` and fill in your credentials:
|
||||||
```
|
```env
|
||||||
DISCORD_TOKEN=your_discord_bot_token
|
DISCORD_TOKEN=your_discord_bot_token
|
||||||
|
CLIENT_ID=your_discord_application_id
|
||||||
LAVALINK_HOST=127.0.0.1
|
LAVALINK_HOST=127.0.0.1
|
||||||
LAVALINK_PORT=2333
|
LAVALINK_PORT=2333
|
||||||
LAVALINK_PASSWORD=your_lavalink_password
|
LAVALINK_PASSWORD=your_lavalink_password
|
||||||
```
|
```
|
||||||
|
2. Install dependencies:
|
||||||
2. Build the project:
|
|
||||||
```sh
|
```sh
|
||||||
cargo build --release
|
pnpm install
|
||||||
|
```
|
||||||
|
3. Run tests:
|
||||||
|
```sh
|
||||||
|
npm test
|
||||||
|
```
|
||||||
|
4. Register slash commands:
|
||||||
|
```sh
|
||||||
|
npm start # or node deploy-commands.js
|
||||||
|
```
|
||||||
|
5. Start the bot:
|
||||||
|
```sh
|
||||||
|
npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Run the bot:
|
## Docker
|
||||||
|
|
||||||
|
A `Dockerfile` and `docker-compose.yml` are provided for containerized deployment.
|
||||||
|
|
||||||
|
- Build and run with Docker Compose:
|
||||||
```sh
|
```sh
|
||||||
cargo run --release
|
docker-compose up --build
|
||||||
```
|
```
|
||||||
|
- Environment variables are loaded from `.env`.
|
||||||
|
- Lavalink service is configured in `docker-compose.yml` alongside the bot.
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
- `src/main.rs` - Bot entry point, initializes Serenity and LavaLink clients
|
- `src/index.js` — Entry point
|
||||||
- `src/handler.rs` - Serenity event handlers (ready, interaction, voice updates)
|
- `src/commands/` — Slash command modules
|
||||||
- `src/lavalink_handler.rs` - LavaLink event handlers
|
- `src/events/` — Discord event handlers
|
||||||
- `src/state.rs` - TypeMap keys for shared state
|
- `src/structures/` — Erela.js (Lavalink) event wiring
|
||||||
- `src/utils.rs` - Utility functions (env management)
|
- `src/utils/logger.js` — Logging setup
|
||||||
- `src/commands/` - Modular slash command definitions and handlers
|
- `deploy-commands.js` — Slash command registration script
|
||||||
|
- `Dockerfile` — Bot container image
|
||||||
## Commands
|
- `docker-compose.yml` — Multi-service setup (bot + Lavalink)
|
||||||
|
|
||||||
- `/ping` - Replies with "Pong!"
|
|
||||||
- `/join` - Bot joins your voice channel
|
|
||||||
- `/play url:<URL>` - Plays audio from the given URL
|
|
||||||
- `/leave` - Bot leaves the voice channel
|
|
||||||
|
|
||||||
## TODO
|
|
||||||
- Implement actual command logic in `src/commands/*.rs`
|
|
||||||
- Add error handling and command concurrency management
|
|
||||||
- Expand LavaLink event handlers
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT
|
MIT
|
||||||
24
docker-compose.yml
Normal file
24
docker-compose.yml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
lavalink:
|
||||||
|
image: jagrosh/lavalink:latest
|
||||||
|
container_name: lavalink
|
||||||
|
ports:
|
||||||
|
- "2333:2333"
|
||||||
|
environment:
|
||||||
|
- LAVALINK_PASSWORD=${LAVALINK_PASSWORD}
|
||||||
|
volumes:
|
||||||
|
# Optional: mount custom configuration if needed
|
||||||
|
# - ./application.yml:/opt/Lavalink/application.yml
|
||||||
|
|
||||||
|
bot:
|
||||||
|
build: .
|
||||||
|
container_name: discord-music-bot
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
environment:
|
||||||
|
- LAVALINK_HOST=lavalink
|
||||||
|
- LAVALINK_PORT=2333
|
||||||
|
depends_on:
|
||||||
|
- lavalink
|
||||||
Loading…
x
Reference in New Issue
Block a user