From 228d0bef6941cfc493d90f2d8ce9980c09da8609 Mon Sep 17 00:00:00 2001 From: aki Date: Thu, 24 Apr 2025 16:09:28 +0800 Subject: [PATCH] feat: Add YouTube OAuth Token to environment configuration and update README --- .env.example | 4 ++ README.md | 150 ++++++++++++++++++++++++++++++++++----------------- 2 files changed, 106 insertions(+), 48 deletions(-) diff --git a/.env.example b/.env.example index b04d23f..4dc65ed 100644 --- a/.env.example +++ b/.env.example @@ -15,3 +15,7 @@ LAVALINK_PASSWORD=your_password_here # Logging Level (e.g., debug, info, warn, error) 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 diff --git a/README.md b/README.md index f8919de..0890cea 100644 --- a/README.md +++ b/README.md @@ -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 -- Slash commands: `/ping`, `/join`, `/play`, `/leave` -- Lavalink integration for audio playback -- Modular command handler structure +- Slash commands (e.g., `/ping`, `/join`, `/play`, `/leave`) +- `shoukaku` integration for robust Lavalink audio playback +- Modular command and event handlers written in TypeScript +- Basic Docker support (`Dockerfile`, `docker-compose.yml`) ## Prerequisites -- Node.js (>=14) -- pnpm or npm -- A Discord application with bot token -- LavaLink server for audio streaming +- Node.js (>=16 recommended, check `package.json` for specific engine requirements) +- pnpm (recommended) or npm +- TypeScript (`typescript` package, usually installed as a dev dependency) +- A Discord application with bot token and client ID +- A running Lavalink server ## Setup -1. Copy `.env.example` to `.env` and fill in your credentials: - ```env - DISCORD_TOKEN=your_discord_bot_token - CLIENT_ID=your_discord_application_id - LAVALINK_HOST=127.0.0.1 - LAVALINK_PORT=2333 - LAVALINK_PASSWORD=your_lavalink_password - ``` -2. Install dependencies: - ```sh - pnpm install - ``` -3. Run tests: - ```sh - pnpm test - ``` -4. Register slash commands: - ```sh - pnpm start # or node deploy-commands.js - ``` -5. Start the bot: - ```sh - pnpm start - ``` +1. **Clone the repository:** + ```sh + git clone + cd discord-music-bot + ``` +2. **Install dependencies:** + ```sh + pnpm install + ``` +3. **Configure Environment:** + Copy `.env.example` to `.env` and fill in your credentials: + ```dotenv + # Discord Bot Token (Required) + DISCORD_TOKEN=your_discord_bot_token + + # Discord Application Client ID (Required for command deployment) + CLIENT_ID=your_discord_application_id + + # Discord Guild ID (Optional, for deploying commands to a specific test server) + # GUILD_ID=your_guild_id_here + + # Lavalink Configuration (Required) + 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 A `Dockerfile` and `docker-compose.yml` are provided for containerized deployment. -- Build and run with Docker Compose: - ```sh - docker-compose up --build - ``` -- Environment variables are loaded from `.env`. -- Lavalink service is configured in `docker-compose.yml` alongside the bot. +- Ensure your `.env` file is configured correctly. +- Build and run with Docker Compose: + ```sh + docker-compose up --build -d # Use -d to run in detached mode + ``` +- The `docker-compose.yml` includes both the bot service and a Lavalink service. ## Project Structure -- `src/index.js` — Entry point -- `src/commands/` — Slash command modules -- `src/events/` — Discord event handlers -- `src/structures/` — Erela.js (Lavalink) event wiring -- `src/utils/logger.js` — Logging setup -- `deploy-commands.js` — Slash command registration script -- `Dockerfile` — Bot container image -- `docker-compose.yml` — Multi-service setup (bot + Lavalink) +``` +. +├── src/ # Source code directory +│ ├── commands/ # Slash command modules (.ts) +│ ├── events/ # Discord.js and Shoukaku event handlers (.ts) +│ ├── structures/ # Custom structures or base classes (e.g., Shoukaku event handlers) +│ ├── utils/ # Utility functions (e.g., logger.ts) +│ └── 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 -MIT +This project is licensed under the **GNU General Public License v3.0**. See the [LICENSE](LICENSE) file for details.