UNPKG

discord-play

Version:

A robust wrapper module for @discordjs/voice, implementing functions and emitting events making it easier to interact with the new voice module.

84 lines 3.22 kB
/// <reference types="node" /> import { AudioPlayer, AudioResource } from '@discordjs/voice'; import { Readable } from 'node:stream'; import { TypedEmitter } from 'tiny-typed-emitter'; import { PlayerEvents } from '../interfaces/events'; import { PlayOptions } from '../interfaces/interfaces'; /** * The audio player class of `discord-play`. * * Must be created only after a voice connection is * established, either through a {@link DisPlayConnection} instance or the @discordjs/voice * `joinVoiceChannel` function. */ export declare class DisPlayPlayer extends TypedEmitter<PlayerEvents> { /** * The {@link AudioPlayer} instance from @discordjs/voice. */ readonly player: AudioPlayer; /** * Stores previous volume amount before muting the player, which can be restored back * when unmuting the player. */ private volumeCache; /** * Attaches logic to the audio player and binds it to the voice connection. * @param guildId - The ID of the guild where the voice connection is established. */ constructor(guildId: string); /** * Plays the input audio resource, and any previously playing resource gets destroyed and replaced. * @param resource - The audio resouce. */ play(resource: AudioResource): void; /** * Plays from input source provided. * @param source - Can be either : * - Audio url i.e. local path or a url with audio endpoint (will require ffmpeg). * - Readable stream of audio data. * @param options - {@link PlayOptions} */ play(source: string | Readable, options?: PlayOptions): void; /** * Stops the audio player and destroys any underlying resource. * @returns `true` if the player will come to a stop, otherwise `false`. */ stop(): boolean; /** * Pauses/unpauses the audio player. * @returns `true` if player is paused, else `false` i.e. unpaused. */ togglePause(): boolean; /** * Returns the amount of volume in percentage (0 to 100) of the player resource. * @remarks * Returns percentage of volume else undefined if player doesn't have any underlying resource * or resource doesn't have inline volume enabled (has 100% volume). */ get volume(): number | undefined; /** * Changes volume of the underlying resource of the player. * @param volume - Percentage of volume to set (0 to 100). * @returns `true` if volume is changed successfully, otherwise `false`. * * @remarks * Works only when inline volume of resource was enabled. */ setVolume(volume: number): boolean; /** * Mutes/Unmutes the audio player. * @returns `true` if player was muted, otherwise `false`. * * @remarks * Requires the currently playing audio resource to have inline volume enabled. * * @throws Error if resource doesn't have inline volume enabled. */ toggleMute(): boolean; /** * To detect if currently underlying resource (if any) has inline volume enabled or not. * @returns `true` if inline volume is enabled, otherwise `false`. */ private isVolumeChangeable; } //# sourceMappingURL=player.d.ts.map