# naser-abdulrahman/discord-music-bot architecture

> Architecture diagram of the GitHub repository naser-abdulrahman/discord-music-bot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/naser-abdulrahman/discord-music-bot
- Repository: https://github.com/naser-abdulrahman/discord-music-bot

## Overview

This is a Discord music bot: users submit commands or interactive search selections, tracks are resolved from YouTube or Spotify, added to a shared queue, downloaded or resolved to local audio, and played in a Discord voice channel. The graph also preserves playlist import, explicit-track filtering, queue controls, and local-file playback. Several command implementations and configuration wiring were not fully excerpted, so only documented or excerpt-supported relationships are shown; external-service links reflect the shown integrations.

Main entry points: [`main.py`](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/main.py) (Bot entry and commands), [`state.py`](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/state.py) (Shared song queue), [`audio.py`](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/audio.py) (Playback orchestration), [`ui.py`](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/ui.py) (Interactive search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_commands["Discord commands"]
  node_bot["Bot entry and commands<br/>[main.py]"]
  node_playlist["Playlist import<br/>[main.py]"]
  node_explicit["Explicit filtering<br/>[main.py]"]
  node_spotify_cmd["Spotify import command<br/>[main.py]"]
  node_search_ui["Interactive search<br/>[ui.py]"]
  node_queue_controls["Queue controls<br/>[main.py]"]
end

subgraph group_resolve["Track resolution"]
  node_search["YouTube search<br/>[utils.py]"]
  node_playlist_extract["Playlist extraction<br/>[utils.py]"]
  node_spotify_resolve["Spotify track expansion<br/>[utils.py]"]
  node_explicit_lookup["Explicit-track lookup<br/>[utils.py]"]
end

subgraph group_playback["Queue and playback"]
  node_queue[("Shared song queue<br/>[state.py]")]
  node_audio["Playback orchestration<br/>[audio.py]"]
  node_source["Audio source and download<br/>[audio.py]"]
end

subgraph group_integrations["External integrations"]
  node_config["Credentials and settings<br/>[config.py]"]
  node_discord(("Discord voice and UI"))
  node_youtube["YouTube via yt-dlp"]
  node_spotify["Spotify API"]
  node_ffmpeg["FFmpeg audio output"]
end

node_user(("Discord user"))

node_user -->|"sends commands"| node_bot
node_user -->|"chooses results"| node_search_ui
node_bot -->|"handles playlist input"| node_playlist
node_bot -->|"filters requested tracks"| node_explicit
node_bot -->|"handles Spotify URLs"| node_spotify_cmd
node_bot -->|"searches queries"| node_search
node_bot -->|"extracts playlist entries"| node_playlist_extract
node_bot -->|"looks up explicit versions"| node_explicit_lookup
node_bot -->|"expands Spotify URL"| node_spotify_resolve
node_bot -->|"adds tracks"| node_queue
node_bot -->|"starts playback"| node_audio
node_bot -->|"handles queue requests"| node_queue_controls
node_search_ui -->|"enqueues selections"| node_queue
node_search_ui -->|"starts selected track"| node_audio
node_search_ui -->|"updates interactive view"| node_discord
node_playlist -->|"adds playlist tracks"| node_queue
node_explicit -->|"adds filtered tracks"| node_queue
node_spotify_cmd -->|"adds expanded tracks"| node_queue
node_search -->|"queries yt-dlp"| node_youtube
node_playlist_extract -->|"extracts entries"| node_youtube
node_explicit_lookup -->|"searches explicit terms"| node_search
node_spotify_resolve -->|"retrieves track metadata"| node_spotify
node_config -->|"supplies credentials"| node_spotify_resolve
node_audio -->|"dequeues next track"| node_queue
node_audio -->|"resolves next audio"| node_source
node_audio -->|"plays in voice channel"| node_discord
node_source -->|"resolves ytsearch"| node_search
node_source -->|"downloads audio"| node_youtube
node_source -->|"creates audio stream"| node_ffmpeg

click node_bot "https://github.com/naser-abdulrahman/discord-music-bot/blob/master/main.py"
click node_playlist "https://github.com/naser-abdulrahman/discord-music-bot/blob/master/main.py"
click node_explicit "https://github.com/naser-abdulrahman/discord-music-bot/blob/master/main.py"
click node_spotify_cmd "https://github.com/naser-abdulrahman/discord-music-bot/blob/master/main.py"
click node_search_ui "https://github.com/naser-abdulrahman/discord-music-bot/blob/master/ui.py"
click node_queue_controls "https://github.com/naser-abdulrahman/discord-music-bot/blob/master/main.py"
click node_search "https://github.com/naser-abdulrahman/discord-music-bot/blob/master/utils.py"
click node_playlist_extract "https://github.com/naser-abdulrahman/discord-music-bot/blob/master/utils.py"
click node_spotify_resolve "https://github.com/naser-abdulrahman/discord-music-bot/blob/master/utils.py"
click node_explicit_lookup "https://github.com/naser-abdulrahman/discord-music-bot/blob/master/utils.py"
click node_queue "https://github.com/naser-abdulrahman/discord-music-bot/blob/master/state.py"
click node_audio "https://github.com/naser-abdulrahman/discord-music-bot/blob/master/audio.py"
click node_source "https://github.com/naser-abdulrahman/discord-music-bot/blob/master/audio.py"
click node_config "https://github.com/naser-abdulrahman/discord-music-bot/blob/master/config.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_bot,node_playlist,node_explicit,node_spotify_cmd,node_search_ui,node_queue_controls,node_user toneBlue
class node_search,node_playlist_extract,node_spotify_resolve,node_explicit_lookup toneAmber
class node_queue,node_audio,node_source toneMint
class node_config,node_discord,node_youtube,node_spotify,node_ffmpeg toneRose
```

## Components

### Discord commands

- [Bot entry and commands](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/main.py): `main.py`
- [Playlist import](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/main.py): `main.py`
- [Explicit filtering](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/main.py): `main.py`
- [Spotify import command](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/main.py): `main.py`
- [Interactive search](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/ui.py): `ui.py`
- [Queue controls](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/main.py): `main.py`

### Track resolution

- [YouTube search](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/utils.py): `utils.py`
- [Playlist extraction](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/utils.py): `utils.py`
- [Spotify track expansion](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/utils.py): `utils.py`
- [Explicit-track lookup](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/utils.py): `utils.py`

### Queue and playback

- [Shared song queue](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/state.py): `state.py`
- [Playback orchestration](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/audio.py): `audio.py`
- [Audio source and download](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/audio.py): `audio.py`

### External integrations

- [Credentials and settings](https://github.com/naser-abdulrahman/discord-music-bot/blob/master/config.py): `config.py`
- **Discord voice and UI**
- **YouTube via yt-dlp**
- **Spotify API**
- **FFmpeg audio output**

### Other components

- **Discord user**

## Connections

- Discord user → Bot entry and commands: sends commands (evidence: `README.md`)
- Discord user → Interactive search: chooses results (evidence: `README.md`)
- Bot entry and commands → Playlist import: handles playlist input (evidence: `main.py`)
- Bot entry and commands → Explicit filtering: filters requested tracks (evidence: `main.py`)
- Bot entry and commands → Spotify import command: handles Spotify URLs (evidence: `main.py`)
- Bot entry and commands → YouTube search: searches queries (evidence: `main.py`)
- Bot entry and commands → Playlist extraction: extracts playlist entries (evidence: `main.py`)
- Bot entry and commands → Explicit-track lookup: looks up explicit versions (evidence: `main.py`)
- Bot entry and commands → Spotify track expansion: expands Spotify URL (evidence: `main.py`)
- Bot entry and commands → Shared song queue: adds tracks (evidence: `main.py`)
- Bot entry and commands → Playback orchestration: starts playback (evidence: `main.py`)
- Bot entry and commands → Queue controls: handles queue requests (evidence: `README.md`)
- Interactive search → Shared song queue: enqueues selections (evidence: `ui.py`)
- Interactive search → Playback orchestration: starts selected track (evidence: `ui.py`)
- Interactive search → Discord voice and UI: updates interactive view (evidence: `ui.py`)
- Playlist import → Shared song queue: adds playlist tracks (evidence: `main.py`)
- Explicit filtering → Shared song queue: adds filtered tracks (evidence: `main.py`)
- Spotify import command → Shared song queue: adds expanded tracks (evidence: `main.py`)
- YouTube search → YouTube via yt-dlp: queries yt-dlp (evidence: `utils.py`)
- Playlist extraction → YouTube via yt-dlp: extracts entries (evidence: `utils.py`)
- Explicit-track lookup → YouTube search: searches explicit terms (evidence: `utils.py`)
- Spotify track expansion → Spotify API: retrieves track metadata (evidence: `utils.py`)
- Credentials and settings → Spotify track expansion: supplies credentials (evidence: `utils.py`)
- Playback orchestration → Shared song queue: dequeues next track (evidence: `audio.py`)
- Playback orchestration → Audio source and download: resolves next audio (evidence: `audio.py`)
- Playback orchestration → Discord voice and UI: plays in voice channel (evidence: `audio.py`)
- Audio source and download → YouTube search: resolves ytsearch (evidence: `audio.py`)
- Audio source and download → YouTube via yt-dlp: downloads audio (evidence: `audio.py`)
- Audio source and download → FFmpeg audio output: creates audio stream (evidence: `audio.py`)
