Overview
Snax is a high-performance, robust, and clean Discord music bot built on top of Discord.js v14. It utilizes Lavalink (via the Kazagumo wrapper and Shoukaku connector) to deliver ultra-low latency, crystal-clear audio streaming.
By offloading audio decoding and streaming tasks to a dedicated Lavalink node, Snax achieves maximum resource efficiency, stability, and zero stuttering, even when playing large playlists. It supports hybrid controls: classic prefix commands (default: $) and modern Application slash (/) commands.
Primary Function: Dedicated Music Playback & Controller UI
Default Prefix: $ (customizable per-server using $setprefix)
Project Structure
Snax-Bot/
├── index.js — App bootstrap and client login
├── config/
│ ├── config.json — Default configuration settings
│ ├── config.js — Environment wrapper merging config with .env
│ ├── slashOptionsMap.js — Options layout for slash commands
│ └── activity.json — Status activity definitions
├── lavalink_music/ — Music sub-system module
│ ├── commands/ — Music command script executors (13 commands)
│ ├── events/ — Lavalink Node and player event listeners
│ ├── embeds.js — UI Builders for playback controller embeds
│ ├── interaction.js — Controller button component interaction handlers
│ └── player.js — Connection configurations and Kazagumo player manager
├── events/ — Client-wide Discord gateway events
├── utils/ — Core utilities
│ ├── antiSpam.js — rolling-window spam prevention algorithm
│ ├── serverLogger.js — Auditing channel creation & log logger
│ ├── globalLogger.js — Home server log manager (tracks bot status)
│ ├── logger.js — Colorized terminal logging utilities
│ ├── slashDeploy.js — Slash commands publisher API
│ └── voiceCheck.js — Voice channel state validator
├── install.bat — 1-click Windows installer script
└── setup_mac.sh — 1-click macOS/Linux installation script
Setup & Installation
Prerequisites
- Node.js v18 or higher — nodejs.org
- Discord Bot Token — Discord Developer Portal
- Lavalink Server Node — self-hosted or public node credentials
Installation Steps
-
Run Setup script:
- Windows: Double-clickinstall.bat
- macOS/Linux: Runbash setup_mac.shin terminal -
Configure `.env` settings: Configure your secret tokens and Lavalink node details in the newly created
.envfile (see Configuration section). -
Start the bot: Execute
node index.jsin the console.
Configuration
Environment Secrets (.env)
Bot_Token=YOUR_DISCORD_BOT_TOKEN
OWNER_ID=YOUR_USER_ID
LAVALINK_HOST=LAVALINK_NODE_IP_OR_HOST
LAVALINK_PORT=LAVALINK_NODE_PORT
LAVALINK_PASSWORD=LAVALINK_NODE_PASSWORD
LAVALINK_SECURE=true_OR_false
Runtime Settings (config/config.json)
| Field | Default | Description |
|---|---|---|
| prefix | "$" | Default prefix for text commands. |
| defaultVolume | 100 | Starting volume scale (0-100). |
| leaveOnEmpty | true | Leave VC when all other members disconnect. |
| leaveOnEmptyCooldown | 30000 | Cooldown in ms before leaving empty VC. |
| leaveOnEnd | false | Leave VC when the queue finishes. |
| selfDeaf | true | Deafens the bot to reduce bandwidth. |
| embed.color | "#5865F2" | Primary hex color used for rich embeds. |
Music System (Lavalink)
The music system runs independently inside the lavalink_music/ subsystem, leveraging Shoukaku and Kazagumo wrappers. This architecture abstracts node management and queue handling.
Audio Playback Pipeline
- Command: The user executes
$play <query>. - VC Check:
voiceCheck.jsensures the member and bot are in compatible voice channels. - Player Resolve: Retrieves the existing player instance or initializes one using
player.createPlayer(). - Track Search: Kazagumo queries Lavalink. If a playlist is resolved, all tracks load. YouTube Shorts are converted automatically.
- Lavalink Streaming: Lavalink decodes and streams the track directly to Discord's voice servers, avoiding server CPU bottle-necking.
Interactive Controller Cards
When a track begins playing, the bot sends an embed controller interface. Users can interact via buttons:
- ⏯️ Play/Pause: Toggles current track pause state.
- ⏭️ Skip: Plays the next queued song.
- ⏹️ Stop: Clears queue, stops player, and disconnects.
- 🔄 Loop/LoopQ: Loops track or loop queue.
- 🔀 Shuffle: Re-orders the queue.
- ➕ Autoplay: Automates endless queue generation.
Anti-Spam System
An in-memory rolling 10-second window tracks message frequency. If a user exceeds threshold limits executing commands, the bot penalizes them.
| User Tier | Warning (10s) | Timeout Penalty (10s) |
|---|---|---|
| Normal User | 4 commands | 7 commands (2-minute timeout) |
| BypassExe Holders | 15 commands | 20 commands (2-minute timeout) |
| SupBypass / Admins / Owners | Immune | Immune (No limits applied) |
Event Reference
Discord Client Gateway Events
- ready: Establishes activity presence; fetches application owner ID dynamically.
- messageCreate: Evaluates prefix/mentions, runs anti-spam filters, checks default command group mappings, and executes commands.
- interactionCreate: Handles slash commands and interactive buttons.
- guildCreate: Automatically establishes a private
#snax-logchannel on server entry.
Lavalink Player Lifecycle Events
- playerStart: Fires when a track begins, dispatching the controller embed interface.
- playerEmpty: Fires when the queue ends, alerting the text channel.
- error: Logs node connection exceptions.
Utility Modules
- utils/permissions.js: Handles local prefix cache settings. Sets up default group access (which maps
@everyonefor music). - utils/antiSpam.js: Rate-limiting tracker maps.
- utils/serverLogger.js: Establishes private channel logging workflows.
- utils/voiceCheck.js: Ensures users are in a voice channel before sending playback instructions.
Dependencies
| Package | Required Version | Purpose |
|---|---|---|
| discord.js | ^14.26.4 | Core Discord gateway API integration |
| dotenv | ^17.4.2 | Loads variables from local .env environment |
| kazagumo | ^3.4.3 | Lavalink queue controller & track parser |
| shoukaku | ^4.3.0 | Lavalink WebSocket wrapper connector |
Notes & Limitations
- Voice State Permissions: Ensure your bot application has the Privileged
Voice State Intentenabled in the Discord Developer Portal, alongsideMessage Content. - Lavalink Node: Snax relies on an active Lavalink server node. If the node falls offline, music commands will fail with connection exception logs.