Skip to main content

Available Commands

MusicBot provides several commands to control music playback and manage the bot. All commands use the ! prefix.

Command List

Music Playback Commands

!play

Plays audio from YouTube in your voice channel. Syntax:
!play <song name or URL>
Parameters:
  • search_query (required): Either a YouTube URL or a search term
Behavior:
  • Accepts both direct YouTube URLs (starting with http:// or https://)
  • For search queries, uses YouTube Data API v3 to find the first matching video
  • Downloads audio in MP3 format at 192 kbps quality using yt-dlp
  • Adds songs to a per-guild queue if something is already playing
  • Automatically joins your voice channel if not already connected
  • Uses per-guild caching (stored in music/<guild_id>/ directories)
  • Skips download if the video is already cached
Examples:
!play https://www.youtube.com/watch?v=dQw4w9WgXcQ
!play Never Gonna Give You Up
!play lofi hip hop
Error Handling:
  • Returns error if you’re not in a voice channel
  • Returns error for region-locked, private, or deleted videos
  • Shows “Searching for…” message during search operations
  • Notifies when using cached versions of songs
Source Reference: bot.py:213-411

!skip

Skips the currently playing song and moves to the next in queue. Syntax:
!skip
Behavior:
  • Stops current playback immediately
  • Triggers the song_finished callback which plays the next queued song
  • If queue is empty, playback stops
  • Handles edge cases where playback stopped but state wasn’t cleared
Examples:
!skip
Source Reference: bot.py:413-434

Voice Channel Management

!leave

Disconnects the bot from the voice channel and clears all data. Syntax:
!leave
Behavior:
  • Disconnects from the current voice channel
  • Clears the entire song queue for the guild
  • Resets playback state (current song, queue, timers)
  • Cancels any active inactivity timers
  • Deletes the entire guild cache directory (music/<guild_id>/)
  • Removes all downloaded songs for that server
Examples:
!leave
Source Reference: bot.py:436-484

Utility Commands

!ping

Checks the bot’s voice connection latency. Syntax:
!ping
Behavior:
  • Measures round-trip latency to Discord voice server in milliseconds
  • Only works when bot is connected to a voice channel
  • Warns if latency exceeds 150ms
Examples:
!ping
Example Output:
Voice connection latency for this server: 42.35 ms
Source Reference: bot.py:486-503

!author

Displays information about the bot author. Syntax:
!author
Behavior:
  • Shows bot creator information
  • Displays Discord username and GitHub profile link
Examples:
!author
Example Output:
This bot was made by spyflow (Discord: spyflow, GitHub: https://github.com/spyflow).
Source Reference: bot.py:505-512

!clearcache

Manually clears all downloaded songs for the current server. Syntax:
!clearcache
Behavior:
  • Deletes the guild-specific music directory (music/<guild_id>/)
  • Removes all cached MP3 files for that server
  • Prevents clearing cache if a song from cache is currently playing
  • Requires stopping playback first if songs are playing
Examples:
!clearcache
Safety Notes:
  • Bot prevents cache clearing during active playback
  • Use !leave or skip all songs before clearing cache if needed
Source Reference: bot.py:514-546

Command Prefix

All commands use the ! prefix, configured at bot.py:26:
bot = commands.Bot(command_prefix='!', intents=intents)

Per-Guild Isolation

All playback state is isolated per-guild using the GuildPlayerState class (bot.py:29-46):
  • Separate queues for each server
  • Independent voice connections
  • Isolated cache directories
  • Individual inactivity timers

Inactivity Timeout

The bot automatically disconnects after 300 seconds (5 minutes) of inactivity (bot.py:25):
inactive_time = 300  # Time in seconds before the bot disconnects
The timer resets whenever:
  • A new song starts playing
  • The !play command is used

Error Handling

All commands include comprehensive error handling:
  • User not in voice channel
  • Bot in different voice channel
  • Invalid or unavailable videos
  • Network/API errors
  • File system errors
  • yt-dlp download errors

Build docs developers (and LLMs) love