Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/content/docs/basics/voice.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ await player.voices.connect(guildId, voiceChannelId, {

If a connection to the same guild and channel is already in progress, `connect()` returns the existing promise rather than starting a new one. If the bot is already connected to that channel and the connection is live, it returns the existing `VoiceState` immediately.

`connect()` times out after 30 seconds if the gateway events don't arrive.
`connect()` times out after `voiceTimeout` milliseconds (default 10_000 / 10s) if the gateway events don't arrive.

#### Why a connection might fail

Expand Down
52 changes: 28 additions & 24 deletions src/main/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,15 @@ export class Player<
}

/**
* Returns the queue of a guild
* Get the queue of a guild
* @param guildId Id of the guild
* @param error Whether to throw an error if queue is not found
*/
getQueue(guildId: string): Queue<Context> | undefined;
/**
* Get the queue of a guild
* @param guildId Id of the guild
* @param error Whether to throw an error if no queue is found
*/
getQueue(guildId: string, error: true): Queue<Context>;
getQueue(guildId: string, error?: true) {
const queue = this.queues.get(guildId);
Expand All @@ -124,15 +128,15 @@ export class Player<
}

/**
* Creates a queue from options
* @param options Options to create from
* Create (or get) the queue of a guild
* @param options Options for customization
*/
async createQueue(options: CreateQueueOptions<Context>) {
return this.queues.create(options);
}

/**
* Destroys the queue of a guild
* Destroy the queue of a guild
* @param guildId Id of the guild
* @param reason Reason for destroying
*/
Expand All @@ -141,8 +145,8 @@ export class Player<
}

/**
* Searches for results based on query and options
* @param query Query (or URL as well)
* Search tracks by query
* @param query Query or URL
* @param options Options for customization
*/
async search(query: string, options?: SearchOptions): Promise<SearchResult> {
Expand Down Expand Up @@ -171,7 +175,7 @@ export class Player<
}

/**
* Adds or searches if source is query and resumes the queue if stopped
* Add (or search) and play the first resolvable track from source
* @param source Source to play from
* @param options Options for customization
*/
Expand All @@ -193,40 +197,40 @@ export class Player<
}

/**
* Jumps to the specified index in queue of a guild
* Jump to a specific track in queue
* @param guildId Id of the guild
* @param index Index to jump to
* @param index Index of the track
*/
async jump(guildId: string, index: number) {
return this.getQueue(guildId, true).jump(index);
}

/**
* Pauses the queue of a guild
* Pause the queue of a guild
* @param guildId Id of the guild
*/
async pause(guildId: string) {
return this.getQueue(guildId, true).pause();
}

/**
* Plays the previous track in queue of a guild
* Play the previous track in queue
* @param guildId Id of the guild
*/
async previous(guildId: string) {
return this.getQueue(guildId, true).previous();
}

/**
* Resumes the queue of a guild
* Resume the queue of a guild
* @param guildId Id of the guild
*/
async resume(guildId: string) {
return this.getQueue(guildId, true).resume();
}

/**
* Seeks to a position in the current track of a guild
* Seek to a specific position in the current track
* @param guildId Id of the guild
* @param ms Position in milliseconds
*/
Expand All @@ -235,51 +239,51 @@ export class Player<
}

/**
* Enables or disables autoplay for the queue of a guild
* Set autoplay of a queue
* @param guildId Id of the guild
* @param autoplay Whether to enable autoplay
* @param autoplay Whether to enable autoplay (`false` by default)
*/
setAutoplay(guildId: string, autoplay?: boolean) {
return this.getQueue(guildId, true).setAutoplay(autoplay);
}

/**
* Sets the repeat mode for the queue of a guild
* Set repeat mode of a queue
* @param guildId Id of the guild
* @param repeatMode The repeat mode
* @param repeatMode `track`, `queue`, `none` (`none` by default)
*/
setRepeatMode(guildId: string, repeatMode: RepeatMode) {
return this.getQueue(guildId, true).setRepeatMode(repeatMode);
}

/**
* Sets the volume of the queue of a guild
* Set volume of a queue
* @param guildId Id of the guild
* @param volume The volume to set
* @param volume Numeric value between 0 and 1000
*/
async setVolume(guildId: string, volume: number) {
return this.getQueue(guildId, true).setVolume(volume);
}

/**
* Shuffles tracks for the queue of a guild
* Shuffle tracks of a queue
* @param guildId Id of the guild
* @param includePrevious Whether to pull previous tracks to current
* @param includePrevious Whether to move previous tracks to current
*/
shuffle(guildId: string, includePrevious?: boolean) {
return this.getQueue(guildId, true).shuffle(includePrevious);
}

/**
* Plays the next track in queue of a guild
* Play the next track in queue
* @param guildId Id of the guild
*/
async next(guildId: string) {
return this.getQueue(guildId, true).next();
}

/**
* Stops the queue of a guild
* Stop the queue of a guild
* @param guildId Id of the guild
*/
async stop(guildId: string) {
Expand Down
8 changes: 4 additions & 4 deletions src/node/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ export class NodeManager implements Partial<Map<string, Node>> {
*/
state(name: string): NodeState;
/**
* Check if a node is in a certain state
* Check if a node is in a specific state
* @param name Name of the node
* @param equals Expected state of the node
* @param equals State of the node
*/
state(name: string, equals: NodeState): boolean;
state(name: string, equals?: NodeState) {
Expand All @@ -98,8 +98,8 @@ export class NodeManager implements Partial<Map<string, Node>> {

/**
* Delete a node
* @remarks Only a disconnected node with no queues can be deleted, an error is thrown otherwise
* @param name Name of the node
* @remarks Only a disconnected node with no queues can be deleted, an error is thrown otherwise
*/
delete(name: string) {
const node = this.#nodes.get(name);
Expand Down Expand Up @@ -201,7 +201,7 @@ export class NodeManager implements Partial<Map<string, Node>> {
}

/**
* Fetch info for a specific node (cache-first)
* Fetch lavalink info of a node (cache-first)
* @param name Name of the node
*/
async fetchInfo(name: string) {
Expand Down
12 changes: 6 additions & 6 deletions src/queue/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export class FilterManager<PluginFilters extends JsonObject = CommonPluginFilter
}

/**
* Raw player filters object.
* For reference or advanced usage only, deep/shallow copy before mutating
* Raw lavalink player filters object.
* For reference or advanced usage only
*/
get current() {
return this.#player.filters as Filters<PluginFilters>;
Expand Down Expand Up @@ -72,8 +72,8 @@ export class FilterManager<PluginFilters extends JsonObject = CommonPluginFilter
}

/**
* Remove filter(s)
* @param names Name(s) of filter(s) to remove
* Remove filters by name
* @param names Names of filters to remove
*/
async remove<Name extends FilterNames<PluginFilters>>(...names: Name[]) {
if (names.length === 0) return this.#player.filters as Filters<PluginFilters>;
Expand All @@ -88,8 +88,8 @@ export class FilterManager<PluginFilters extends JsonObject = CommonPluginFilter
}

/**
* Clear filters by type (all if none specified)
* @param type Type of filters to clear (`native` for built-in, `plugin` for plugins)
* Remove filters by type (all if none specified)
* @param type `native` for built-in, `plugin` for plugins
*/
async clear(type?: "native" | "plugin") {
switch (type) {
Expand Down
10 changes: 5 additions & 5 deletions src/queue/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class QueueManager<Context extends Record<string, unknown> = QueueContext

/**
* Raw lavalink player objects.
* For reference or advanced usage only, do not `set` or `delete`
* For reference or advanced usage only
*/
get cache() {
return this.#cache as ReadonlyMap<string, APIPlayer>;
Expand Down Expand Up @@ -145,11 +145,11 @@ export class QueueManager<Context extends Record<string, unknown> = QueueContext
}

/**
* Sync multiple lavalink player data
* Sync queues and their lavalink players by node
* @param node Name of the node
* @param target Target to update (`local` for queues, `remote` for node)
* @param target `local` for queue, `remote` for node (`local` by default)
*/
async sync(node: string, target: "local" | "remote" = "local") {
async sync(node: string, target: Parameters<Queue["sync"]>[0] = "local") {
const _node = this.player.nodes.get(node);

if (!_node) throw new Error(`Node '${node}' not found`);
Expand Down Expand Up @@ -185,7 +185,7 @@ export class QueueManager<Context extends Record<string, unknown> = QueueContext
}

/**
* Relocate all queues of a specific node
* Relocate queues by node
* @param node Name of the node
*/
async relocate(node: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/types/main/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export interface PlayerOptions<Plugins extends PlayerPlugin[] = PlayerPlugin[]>
* Return empty or populated array of related tracks
* @param queue The queue requesting track(s)
* @param track The track suggested for reference
* @remarks DO NOT throw an error
* @remarks Do NOT throw an error through this function
*/
fetchRelatedTracks?: (queue: Queue, track: Track) => Promise<Track[]>;
}
Expand Down
4 changes: 2 additions & 2 deletions src/voice/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class VoiceManager implements Partial<Map<string, VoiceState>> {

/**
* Raw voice state objects.
* For reference or advanced usage only, do not `set` or `delete`
* For reference or advanced usage only
*/
get cache() {
return this.#cache as ReadonlyMap<string, BotVoiceState>;
Expand Down Expand Up @@ -96,7 +96,7 @@ export class VoiceManager implements Partial<Map<string, VoiceState>> {
* Connect to a voice channel
* @param guildId Id of the guild
* @param voiceId Id of the voice channel
* @param options Options for the queue
* @param options Options for the queue to be created
*/
async connect(guildId: string, voiceId: string, options?: ConnectOptions) {
if (!isString(guildId, SnowflakeRegex)) throw new Error("Guild Id is not a valid Discord Id");
Expand Down
4 changes: 2 additions & 2 deletions src/voice/region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import type { Player } from "@/main";
import type { PlayerState, VoiceNodePingStats } from "@/types";

/**
* Class representing a voice region and evaluating performing nodes
* Class representing a voice region, tracking latency of ready nodes
*/
export class VoiceRegion {
#stats = new Map<string, VoiceNodePingStats>();

/**
* Id of the region
* Id of this region
*/
readonly id: string;
readonly player: Player;
Expand Down
Loading
Loading