UNPKG

@persian-caesar/discord-player

Version:

Type definitions and helpers for a Discord music player (MusicPlayer) without external dependencies

110 lines (109 loc) 3.59 kB
import { VoiceChannel, TypedEmitter, TrackMetadata } from "./types"; import EventEmitter from "events"; export interface MusicPlayerOptions { autoLeaveOnEmptyQueue?: boolean; autoLeaveOnIdleMs?: number; } /** * MusicPlayer * - Manages voice connection, playback, queue, history, and loop modes * - Emits events defined in MusicPlayerEvent */ export declare class MusicPlayer extends EventEmitter<TypedEmitter> { channel: VoiceChannel; private previousQueueOrder; private connection; private player; private volume; private queue; private history; private loopQueue; private loopTrack; private playing; private autoLeaveOnEmptyQueue; private autoLeaveOnIdleMs; private idleTimer; private shuffield; /** * @param channel The Discord voice channel to connect to * @param initialVolume Initial volume in percent (0–100) * @param options Configuration options (auto-leave, idle timeout) */ constructor(channel: VoiceChannel, initialVolume?: number, options?: MusicPlayerOptions); private startIdleTimer; /** * Search Google and scrape lyrics snippets. * Returns the lyrics or null if not found. * * @param title Song title * @param artist Optional artist name, for more accurate search */ searchLyrics(title: string, artist?: string): Promise<string | null>; private clearIdleTimer; /** * Connect to the voice channel if not already connected. * Waits until the connection is READY or emits an error. */ private ensureConnection; search(query: string): Promise<string>; private createStreamFromScdl; private createStreamFromYtdl; private createStreamFromPlayDl; private fetchMetadata; private playUrl; /** * Play a song by query or URL. * If already playing, adds to queue and emits a queueAdd event. * Otherwise, starts immediate playback via playUrl(). * * @param input YouTube URL or search query (e.g. “Coldplay Yellow”) */ play(input: string): Promise<void>; pause(): void; resume(): void; setVolume(percent: number): void; /** * Handle when the player becomes idle. * - If loopTrack is on, replay current track * - Else if queue has items, play next * - Otherwise, emit finish and optionally disconnect */ private onIdle; skip(): void; /** * Jump to the previous track. * Pops current and last URLs from history, re-queues the current, * and starts playback of the previous one. */ previous(): Promise<void>; /** * Shuffle the queue randomly. * Saves the current queue order so you can undo. */ shuffle(): void; /** * Restore the queue to its previous order, * excluding any tracks that have already been played. */ undoShuffle(): void; toggleLoopQueue(): void; isLoopQueue(): boolean; toggleLoopTrack(): void; isLoopTrack(): boolean; disconnect(): void; stop(noLeave?: boolean): void; getQueue(): TrackMetadata[]; getVolume(): number; isPlaying(): boolean; isPaused(): boolean; isShuffiled(): boolean; private createError; } /** * @copyright * Code by Sobhan-SRZA (mr.sinre) | https://github.com/Sobhan-SRZA * Developed for Persian Caesar | https://github.com/Persian-Caesar | https://dsc.gg/persian-caesar * * If you encounter any issues or need assistance with this code, * please make sure to credit "Persian Caesar" in your documentation or communications. */