feat: Add YouTube OAuth Token to environment configuration and update README

This commit is contained in:
Jose Daniel G. Percy 2025-04-24 16:09:28 +08:00
parent 3c4dc51855
commit 228d0bef69
2 changed files with 106 additions and 48 deletions

View File

@ -15,3 +15,7 @@ LAVALINK_PASSWORD=your_password_here
# Logging Level (e.g., debug, info, warn, error) # Logging Level (e.g., debug, info, warn, error)
LOG_LEVEL=info LOG_LEVEL=info
# YouTube OAuth Token (Optional, for YouTube Music playback via specific plugins)
# See README for instructions on obtaining this.
YOUTUBE_OAUTH_TOKEN=your_youtube_oauth_token_here

150
README.md
View File

@ -1,69 +1,123 @@
# discord-music-bot # Discord Music Bot (TypeScript)
Discord music bot template written in NodeJS using `discord.js` and `erela.js`, with Lavalink support. Discord music bot template written in TypeScript using `discord.js` and `shoukaku`, with Lavalink support.
## Features ## Features
- Slash commands: `/ping`, `/join`, `/play`, `/leave` - Slash commands (e.g., `/ping`, `/join`, `/play`, `/leave`)
- Lavalink integration for audio playback - `shoukaku` integration for robust Lavalink audio playback
- Modular command handler structure - Modular command and event handlers written in TypeScript
- Basic Docker support (`Dockerfile`, `docker-compose.yml`)
## Prerequisites ## Prerequisites
- Node.js (>=14) - Node.js (>=16 recommended, check `package.json` for specific engine requirements)
- pnpm or npm - pnpm (recommended) or npm
- A Discord application with bot token - TypeScript (`typescript` package, usually installed as a dev dependency)
- LavaLink server for audio streaming - A Discord application with bot token and client ID
- A running Lavalink server
## Setup ## Setup
1. Copy `.env.example` to `.env` and fill in your credentials: 1. **Clone the repository:**
```env ```sh
DISCORD_TOKEN=your_discord_bot_token git clone <repository_url>
CLIENT_ID=your_discord_application_id cd discord-music-bot
LAVALINK_HOST=127.0.0.1 ```
LAVALINK_PORT=2333 2. **Install dependencies:**
LAVALINK_PASSWORD=your_lavalink_password ```sh
``` pnpm install
2. Install dependencies: ```
```sh 3. **Configure Environment:**
pnpm install Copy `.env.example` to `.env` and fill in your credentials:
``` ```dotenv
3. Run tests: # Discord Bot Token (Required)
```sh DISCORD_TOKEN=your_discord_bot_token
pnpm test
``` # Discord Application Client ID (Required for command deployment)
4. Register slash commands: CLIENT_ID=your_discord_application_id
```sh
pnpm start # or node deploy-commands.js # Discord Guild ID (Optional, for deploying commands to a specific test server)
``` # GUILD_ID=your_guild_id_here
5. Start the bot:
```sh # Lavalink Configuration (Required)
pnpm start LAVALINK_HOST=lavalink # Or 127.0.0.1 if running locally without Docker Compose
``` LAVALINK_PORT=2333
LAVALINK_PASSWORD=your_lavalink_password
# LAVALINK_SECURE=false # Set to true if Lavalink uses SSL/WSS
# Logging Level (Optional, defaults typically to 'info')
# LOG_LEVEL=info
# YouTube OAuth Token (Optional, needed for YouTube Music via specific plugins)
# See note below on how to obtain this.
YOUTUBE_OAUTH_TOKEN=your_youtube_oauth_token_here
```
**Note on YouTube OAuth Token:**
The `YOUTUBE_OAUTH_TOKEN` is required by some Lavalink plugins (like the `youtube-plugin` potentially used here) to access YouTube Music tracks directly. Obtaining this involves:
1. Go to the [Google Cloud Console](https://console.cloud.google.com/).
2. Create a new project or select an existing one.
3. Navigate to "APIs & Services" -> "Credentials".
4. Click "Create Credentials" -> "OAuth client ID".
5. Select Application type: **"TVs and Limited Input devices"**.
6. Give it a name (e.g., "Lavalink YouTube Music Access").
7. Click "Create". You'll get a Client ID and Client Secret (you likely won't need the secret directly for the token flow).
8. Follow the on-screen instructions or Google's documentation for the "OAuth 2.0 for TV and Limited Input devices" flow. This usually involves visiting a specific URL with your client ID, getting a user code, authorizing the application on a separate device/browser logged into your Google account, and then exchanging the device code for a **refresh token**.
9. Paste the obtained **refresh token** as the value for `YOUTUBE_OAUTH_TOKEN` in your `.env` file.
4. **Build TypeScript (if needed):**
Many setups use `ts-node` for development, but for production, you might need to compile:
```sh
pnpm build # Check package.json for the exact build script
```
5. **Register Slash Commands:**
Run the deployment script (ensure `CLIENT_ID` and `DISCORD_TOKEN` are set in `.env`).
```sh
pnpm deploy # Check package.json for the exact deploy script (might be node/ts-node deploy-commands.ts)
```
6. **Start the Bot:**
```sh
pnpm start # Check package.json for the exact start script (might run compiled JS or use ts-node)
```
## Docker ## Docker
A `Dockerfile` and `docker-compose.yml` are provided for containerized deployment. A `Dockerfile` and `docker-compose.yml` are provided for containerized deployment.
- Build and run with Docker Compose: - Ensure your `.env` file is configured correctly.
```sh - Build and run with Docker Compose:
docker-compose up --build ```sh
``` docker-compose up --build -d # Use -d to run in detached mode
- Environment variables are loaded from `.env`. ```
- Lavalink service is configured in `docker-compose.yml` alongside the bot. - The `docker-compose.yml` includes both the bot service and a Lavalink service.
## Project Structure ## Project Structure
- `src/index.js` — Entry point ```
- `src/commands/` — Slash command modules .
- `src/events/` — Discord event handlers ├── src/ # Source code directory
- `src/structures/` — Erela.js (Lavalink) event wiring │ ├── commands/ # Slash command modules (.ts)
- `src/utils/logger.js` — Logging setup │ ├── events/ # Discord.js and Shoukaku event handlers (.ts)
- `deploy-commands.js` — Slash command registration script │ ├── structures/ # Custom structures or base classes (e.g., Shoukaku event handlers)
- `Dockerfile` — Bot container image │ ├── utils/ # Utility functions (e.g., logger.ts)
- `docker-compose.yml` — Multi-service setup (bot + Lavalink) │ └── index.ts # Main application entry point
├── plugins/ # Lavalink plugins (e.g., youtube-plugin-*.jar)
├── tests/ # Test files
├── .env.example # Example environment variables
├── .gitignore
├── application.yml # Lavalink server configuration
├── deploy-commands.ts # Script to register slash commands
├── docker-compose.yml # Docker Compose configuration for bot + Lavalink
├── Dockerfile # Dockerfile for building the bot image
├── LICENSE # Project License (GPLv3)
├── package.json # Node.js project manifest
├── tsconfig.json # TypeScript compiler options
└── update-plugin.sh # Script to update Lavalink plugins (example)
```
## License ## License
MIT This project is licensed under the **GNU General Public License v3.0**. See the [LICENSE](LICENSE) file for details.