Now-playing panels with discord.py Components V2
How Melodius for Discord builds its now-playing card with discord.py 2.6's LayoutView: four styles, premium-gated presets with a safe fallback, rebuilding on every change, and per-listener accent colours.
Discord's Components V2 lets a bot message be a layout of containers, text, media and buttons instead of an embed with buttons stapled underneath. Melodius for Discord uses it for its now-playing card, through discord.py 2.6's LayoutView.
Why Components V2
An embed has fixed slots. A layout can put artwork beside the song with controls under it, or artwork across the whole card, or a single line. That flexibility is what makes several distinct styles possible from one view class.
Four styles
# Style -> (label, description, premium only)
PRESETS = {
"classic": ("Classic", "Artwork beside the song, with every control", False),
"minimal": ("Minimal", "One line and the essentials", False),
"spotlight": ("Spotlight", "Big artwork across the card", True),
"studio": ("Studio", "Full controls: filters, autoplay, what plays next", True),
}The view resolves the style defensively:
self.preset = (
preset if preset in PRESETS and (premium or not PRESETS[preset][2])
else DEFAULT_PRESET
)Rebuild, don't patch
The card is built again on every change: pause, loop, autoplay. Patching individual components in place means keeping every combination of states consistent by hand; rebuilding from the player's current state makes the card a pure function of that state. The view has no timeout and is stopped when its song ends, so stale buttons never control the next track. Every card also links to the song in Melodius.
Colour per listener
Each listener can pick an accent colour with toggle color, and the bot answers in the colour of whoever it is responding to, falling back to Melodius purple. The current colour lives in a context variable, so deeply nested helpers pick it up without threading it through every call. The Studio card's filter buttons map to the presets in Lavalink audio filters explained.
