LavaPlayer
The LavaPlayer module allows DiSky bots to play audio in voice channels on Discord. It's a powerful audio player with support for various audio sources, making it perfect for music bots.
Overview
LavaPlayer is a powerful audio player library that was originally developed for JDA (Java Discord API). DiSky provides a wrapper for this library, allowing you to easily implement music functionalities in your Discord bot.
With the LavaPlayer module, your bot can:
- Play audio from various sources (YouTube, SoundCloud, direct URLs, etc.)
- Control playback (pause, resume, skip, etc.)
- Manage playlists
- Adjust volume and other playback settings
- Get track information (title, duration, author, etc.)
Getting Started
Installation
- Download the JAR file from here. Be sure you've linked your Patreon account first!
- Place the module JAR file in your server's
plugins/DiSky/modules/
folder
- Restart your server
Basic Concepts
Audio Manager
The audio manager is the core component that handles audio playback for a guild. Each guild has its own audio manager, which allows for independent playback across different servers.
Audio Tracks
An audio track represents a single piece of audio content (like a song) that can be played. Tracks have various properties like title, author, duration, and URL.
Audio Players
The audio player is responsible for actually playing tracks in a voice channel. It provides methods for controlling playback.
Track Scheduler
The track scheduler manages the queue of tracks and determines what to play next. DiSky handles this automatically for you.
Usage Examples
Connecting to a Voice Channel
Before playing music, your bot needs to join a voice channel:
connect bot "bot_name" to voice channel with id "000"
Playing Music
To play a track, you typically:
- Search for or load the track
- Add it to the queue
load items with the url "https://www.youtube.com/watch?v=dQw4w9WgXcQ":
on single track loaded:
add event-track to queue of event-guild
Track Events
DiSky provides several events to handle different track states:
on track start:
send "Now playing: %track title of event-audiotrack%" to console
on track end:
send "Track ended: %track title of event-audiotrack%" to console
Common Use Cases
Music Bot
The most common use case is creating a music bot that can play tracks from YouTube or other sources. Users can queue tracks, skip them, adjust volume, and so on.
Sound Effects
You can use LavaPlayer to play sound effects during specific events in your server, enhancing user experience.
Audio Streaming
LavaPlayer can stream audio from various sources, allowing your bot to act as an audio streamer for your server.
Advanced Features
Track Loading
The module supports different track loading scenarios:
- Single track loading
- Playlist loading
- Search results
- Load failure handling
Track Manipulation
You can manipulate the playback with various effects:
- Adjusting volume
- Seeking to specific positions
- Applying audio filters (if supported)
Queue Management
DiSky provides built-in queue management, allowing you to:
- Add tracks to the queue
- Remove tracks from the queue
- Clear the queue
- Shuffle the queue
- Loop tracks or the entire queue
Best Practices
Error Handling: Always handle load failures and track exceptions to ensure your bot remains stable.
Resource Management: Disconnect the bot from voice channels when not in use to save resources.
User Experience: Provide feedback about the current track, queue status, and player controls.
Permission Checks: Ensure that only authorized users can control the music playback.
Troubleshooting
- If you're having issues with audio playback, ensure your bot has the necessary permissions in the voice channel.
- Some audio sources might be region-locked or have restrictions - be sure to handle these cases gracefully.
- Audio quality issues might be related to server bandwidth or Discord limitations.
Integration with Other DiSky Features
LavaPlayer works seamlessly with other DiSky features:
- Use slash commands to control music playback
- Create interactive buttons for player controls
- Utilize embeds to display track information beautifully
For more detailed information and code examples, visit the DiSky Wiki