discord-player 7.0.0-dev.0 → 7.0.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -86,28 +86,6 @@ $ npm install --save ffmpeg-binaries
86
86
 
87
87
  > Use `FFMPEG_PATH` environment variable to load ffmpeg from custom path.
88
88
 
89
- #### Streaming Library
90
-
91
- **The following method is deprecated and will be removed in the future. Please switch to [discord-player-youtubei](https://npmjs.com/discord-player-youtubei).**
92
-
93
- **Not recommended**:
94
-
95
- YouTube streaming is not supported without installing one of the following package. If you want to add support for YouTube playback, you need to install a streaming library. This step is not needed if you do not plan on using youtube source.
96
-
97
- ```bash
98
- $ npm install --save youtube-ext
99
- # or
100
- $ npm install --save play-dl
101
- # or
102
- $ npm install --save @distube/ytdl-core
103
- # or
104
- $ npm install --save yt-stream
105
- # or
106
- $ npm install --save ytdl-core
107
- ```
108
-
109
- Once you have completed these installations, let's proceed with writing a simple music bot.
110
-
111
89
  ### Setup
112
90
 
113
91
  Let's create a main player instance. This instance handles and keeps track of all the queues and its components.
@@ -147,13 +125,31 @@ const { Player, createErisCompat } = require('discord-player');
147
125
  const player = new Player(createErisCompat(client));
148
126
  ```
149
127
 
128
+ Before you add the command, make sure to provide the context to the commands if you wish to use discord-player's hooks (like `useMainPlayer`).
129
+
130
+ ### Before
131
+
132
+ ```js index.js
133
+ // execute the command
134
+ await command.execute(interaction);
135
+ ```
136
+
137
+ ### After
138
+
139
+ ```js index.js
140
+ // execute the command
141
+ await player.context.provide({ guild: interaction.guild }, () => command.execute(interaction));
142
+ ```
143
+
144
+ This allows discord-player to automatically know the current guild and the queue, resulting in cleaner code and seamless integration. This eradicates the need to pass the player instance to the command or use hacks like `client.player = player`.
145
+
150
146
  Let's move on to the command part. You can define the command as per your requirements. We will only focus on the command part:
151
147
 
152
148
  ```js play.js
153
149
  const { useMainPlayer } = require('discord-player');
154
150
 
155
151
  export async function execute(interaction) {
156
- const player = useMainPlayer();
152
+ const player = useMainPlayer(); // get player instance
157
153
  const channel = interaction.member.voice.channel;
158
154
  if (!channel) return interaction.reply('You are not connected to a voice channel!'); // make sure we have a voice channel
159
155
  const query = interaction.options.getString('query', true); // we need input/query to play
package/dist/index.d.ts CHANGED
@@ -12,10 +12,8 @@ import { BridgeProvider } from '@discord-player/extractor';
12
12
  import { RequestOptions } from 'http';
13
13
  import { StreamType, AudioPlayerError, AudioResource, VoiceConnection, AudioPlayer, AudioPlayerStatus } from 'discord-voip';
14
14
  export { AudioPlayer, CreateAudioPlayerOptions, JoinConfig, JoinVoiceChannelOptions, createAudioPlayer, getVoiceConnection, getVoiceConnections, joinVoiceChannel } from 'discord-voip';
15
- import * as _discord_player_ffmpeg from '@discord-player/ffmpeg';
16
- import { FFmpeg } from '@discord-player/ffmpeg';
15
+ import { FFmpegLib } from '@discord-player/ffmpeg';
17
16
  export * from '@discord-player/ffmpeg';
18
- import { downloadOptions } from 'ytdl-core';
19
17
 
20
18
  declare function isErisProxy(client: any): client is Eris.Client;
21
19
  /**
@@ -514,7 +512,7 @@ declare function FFMPEG_ARGS_PIPED(fmt?: string): string[];
514
512
  * @param stream The source stream
515
513
  * @param options FFmpeg stream options
516
514
  */
517
- declare function createFFmpegStream(stream: Readable | Duplex | string, options?: FFmpegStreamOptions): Readable | Duplex | FFmpeg;
515
+ declare function createFFmpegStream(stream: Readable | Duplex | string, options?: FFmpegStreamOptions): Readable | Duplex;
518
516
 
519
517
  type Filters = keyof typeof AudioFilters.filters;
520
518
  type EQPreset = {
@@ -567,7 +565,7 @@ declare class FFmpegFilterer<Meta = unknown> {
567
565
  * @param source The stream source
568
566
  * @param options The stream options
569
567
  */
570
- createStream(source: string | Readable, options: FFmpegStreamOptions): Readable | stream.Duplex | _discord_player_ffmpeg.FFmpeg;
568
+ createStream(source: string | Readable, options: FFmpegStreamOptions): Readable | stream.Duplex;
571
569
  /**
572
570
  * Set ffmpeg filters
573
571
  * @param filters The filters
@@ -1809,27 +1807,19 @@ declare function useContext<T = unsafe>(context: Context<T>): T | undefined;
1809
1807
  * @param node guild queue node resolvable
1810
1808
  */
1811
1809
  declare function useHistory<Meta = unknown>(): GuildQueueHistory<Meta> | null;
1812
- declare function useHistory<Meta = unknown>(node: NodeResolvable): GuildQueueHistory<Meta> | null;
1813
1810
 
1814
1811
  /**
1815
1812
  * Fetch guild queue player node
1816
1813
  * @param node Guild queue node resolvable
1817
1814
  */
1818
1815
  declare function usePlayer<Meta = unknown>(): GuildQueuePlayerNode<Meta> | null;
1819
- declare function usePlayer<Meta = unknown>(node: NodeResolvable): GuildQueuePlayerNode<Meta> | null;
1820
1816
 
1821
1817
  /**
1822
1818
  * Fetch guild queue
1823
1819
  * @param node Guild queue node resolvable
1824
1820
  */
1825
1821
  declare function useQueue<Meta = unknown>(): GuildQueue<Meta> | null;
1826
- declare function useQueue<Meta = unknown>(node: NodeResolvable): GuildQueue<Meta> | null;
1827
1822
 
1828
- /**
1829
- * Fetch main player instance
1830
- * @deprecated
1831
- */
1832
- declare function useMasterPlayer(): Player;
1833
1823
  /**
1834
1824
  * Fetch main player instance
1835
1825
  */
@@ -1842,7 +1832,6 @@ type MetadataDispatch<T> = readonly [() => T, (metadata: T | SetterFN$1<T, T>) =
1842
1832
  * @param node Guild queue node resolvable
1843
1833
  */
1844
1834
  declare function useMetadata<T = unknown>(): MetadataDispatch<T>;
1845
- declare function useMetadata<T = unknown>(node: NodeResolvable): MetadataDispatch<T>;
1846
1835
 
1847
1836
  interface TimelineDispatcherOptions {
1848
1837
  ignoreFilters: boolean;
@@ -1852,7 +1841,7 @@ interface TimelineDispatcherOptions {
1852
1841
  * @param node Guild queue node resolvable
1853
1842
  * @param options Options for timeline dispatcher
1854
1843
  */
1855
- declare function useTimeline(node?: NodeResolvable, options?: Partial<TimelineDispatcherOptions>): {
1844
+ declare function useTimeline(options?: Partial<TimelineDispatcherOptions>): {
1856
1845
  readonly timestamp: PlayerTimestamp;
1857
1846
  readonly volume: number;
1858
1847
  readonly paused: boolean;
@@ -1882,24 +1871,8 @@ type VolumeDispatch = readonly [() => number, (volume: number | SetterFN) => boo
1882
1871
  * @param node Guild queue node resolvable
1883
1872
  */
1884
1873
  declare function useVolume(): VolumeDispatch;
1885
- declare function useVolume(node: NodeResolvable): VolumeDispatch;
1886
-
1887
- declare const instances: Collection<string, Player>;
1888
1874
 
1889
- declare const getPlayer: () => Player | null;
1890
- interface HooksCtx {
1891
- guild: Guild;
1892
- }
1893
- declare const getQueue: <T = unknown>(node: NodeResolvable) => GuildQueue<T> | null;
1894
- interface HookDeclarationContext {
1895
- getQueue: typeof getQueue;
1896
- getPlayer: typeof getPlayer;
1897
- instances: typeof instances;
1898
- }
1899
- type HookDeclaration<T extends (...args: any[]) => any> = (context: HookDeclarationContext) => T;
1900
- declare function createHook<T extends HookDeclaration<(...args: any[]) => any>>(hook: T): ReturnType<T>;
1901
-
1902
- declare const knownExtractorKeys: readonly ["SpotifyExtractor", "AppleMusicExtractor", "SoundCloudExtractor", "YouTubeExtractor", "VimeoExtractor", "ReverbnationExtractor", "AttachmentExtractor"];
1875
+ declare const knownExtractorKeys: readonly ["SpotifyExtractor", "AppleMusicExtractor", "SoundCloudExtractor", "VimeoExtractor", "ReverbnationExtractor", "AttachmentExtractor"];
1903
1876
  type ExtractorLoaderOptionDict = {
1904
1877
  [K in (typeof knownExtractorKeys)[number]]?: ConstructorParameters<typeof _discord_player_extractor[K]>[1];
1905
1878
  };
@@ -2129,10 +2102,6 @@ declare class BaseExtractor<T extends object = object> {
2129
2102
  * @param message The debug message
2130
2103
  */
2131
2104
  debug(message: string): boolean;
2132
- /**
2133
- * IP rotator instance, if available
2134
- */
2135
- get routePlanner(): IPRotator | null;
2136
2105
  /**
2137
2106
  * A flag to indicate `Demuxable` stream support for `opus`/`ogg/opus`/`webm/opus` formats.
2138
2107
  */
@@ -2311,42 +2280,8 @@ declare class VoiceUtils {
2311
2280
  getConnection(guild: Snowflake, group?: string): VoiceConnection | undefined;
2312
2281
  }
2313
2282
 
2314
- declare class IPBlock {
2315
- block: string;
2316
- usage: number;
2317
- readonly cidr: string;
2318
- readonly cidrSize: number;
2319
- constructor(block: string);
2320
- consume(): void;
2321
- }
2322
- interface IPRotationConfig {
2323
- /**
2324
- * IP blocks to use
2325
- */
2326
- blocks: string[];
2327
- /**
2328
- * IPs to exclude
2329
- */
2330
- exclude?: string[];
2331
- /**
2332
- * Max retries to find an IP that is not excluded
2333
- */
2334
- maxRetries?: number;
2335
- }
2336
- declare class IPRotator {
2337
- #private;
2338
- config: IPRotationConfig;
2339
- blocks: IPBlock[];
2340
- failures: Map<string, number>;
2341
- MAX_NEXT_RETRIES: number;
2342
- constructor(config: IPRotationConfig);
2343
- getIP(): {
2344
- ip: string;
2345
- family: 4 | 6;
2346
- };
2347
- isFailedOrExcluded(ip: string): boolean;
2348
- addFailed(ip: string): void;
2349
- static getRandomIP(address: string, start?: number, end?: number): string;
2283
+ interface HooksCtx {
2284
+ guild: Guild;
2350
2285
  }
2351
2286
 
2352
2287
  interface PlayerNodeInitializationResult<T = unknown> {
@@ -2370,7 +2305,6 @@ declare class Player extends PlayerEventsEmitter<PlayerEvents> {
2370
2305
  * The version of discord-player
2371
2306
  */
2372
2307
  static readonly version: string;
2373
- static _singletonKey: symbol;
2374
2308
  /**
2375
2309
  * The unique identifier of this player instance
2376
2310
  */
@@ -2399,10 +2333,6 @@ declare class Player extends PlayerEventsEmitter<PlayerEvents> {
2399
2333
  * The player events channel
2400
2334
  */
2401
2335
  events: PlayerEventsEmitter<GuildQueueEvents<any>>;
2402
- /**
2403
- * The route planner
2404
- */
2405
- routePlanner: IPRotator | null;
2406
2336
  /**
2407
2337
  * The player version
2408
2338
  */
@@ -2427,26 +2357,12 @@ declare class Player extends PlayerEventsEmitter<PlayerEvents> {
2427
2357
  */
2428
2358
  onVoiceStateUpdate(handler: VoiceStateHandler): void;
2429
2359
  debug(m: string): boolean;
2430
- /**
2431
- * Creates discord-player singleton instance.
2432
- * @param client The client that instantiated player
2433
- * @param options Player initializer options
2434
- */
2435
- static singleton(client: Client, options?: Omit<PlayerInitOptions, 'ignoreInstance'>): Player;
2436
2360
  /**
2437
2361
  * Creates new discord-player instance.
2438
2362
  * @param client The client that instantiated player
2439
2363
  * @param options Player initializer options
2440
2364
  */
2441
- static create(client: Client, options?: Omit<PlayerInitOptions, 'ignoreInstance'>): Player;
2442
- /**
2443
- * Get all active master player instances
2444
- */
2445
- static getAllPlayers(): Player[];
2446
- /**
2447
- * Clear all master player instances
2448
- */
2449
- static clearAllPlayers(): void;
2365
+ static create(client: Client, options?: PlayerInitOptions): Player;
2450
2366
  /**
2451
2367
  * The current query cache provider in use
2452
2368
  */
@@ -2470,7 +2386,6 @@ declare class Player extends PlayerEventsEmitter<PlayerEvents> {
2470
2386
  *
2471
2387
  * // outputs something like
2472
2388
  * // {
2473
- * // instances: number,
2474
2389
  * // queuesCount: number,
2475
2390
  * // queryCacheEnabled: boolean,
2476
2391
  * // queues: [
@@ -2483,7 +2398,6 @@ declare class Player extends PlayerEventsEmitter<PlayerEvents> {
2483
2398
  * ```
2484
2399
  */
2485
2400
  generateStatistics(): {
2486
- instances: number;
2487
2401
  queuesCount: number;
2488
2402
  queryCacheEnabled: boolean;
2489
2403
  queues: GuildQueueStatisticsMetadata[];
@@ -3095,10 +3009,6 @@ interface PlaylistJSON {
3095
3009
  tracks: TrackJSON[];
3096
3010
  }
3097
3011
  interface PlayerInitOptions {
3098
- /**
3099
- * The options passed to `ytdl-core`.
3100
- */
3101
- ytdlOptions?: downloadOptions;
3102
3012
  /**
3103
3013
  * The voice connection timeout
3104
3014
  */
@@ -3123,10 +3033,6 @@ interface PlayerInitOptions {
3123
3033
  * Query cache provider
3124
3034
  */
3125
3035
  queryCache?: QueryCacheProvider<any> | null;
3126
- /**
3127
- * Ignore player instance
3128
- */
3129
- ignoreInstance?: boolean;
3130
3036
  /**
3131
3037
  * Use legacy version of ffmpeg
3132
3038
  */
@@ -3135,10 +3041,6 @@ interface PlayerInitOptions {
3135
3041
  * Set bridge provider
3136
3042
  */
3137
3043
  bridgeProvider?: BridgeProvider;
3138
- /**
3139
- * IP rotator config
3140
- */
3141
- ipconfig?: IPRotationConfig;
3142
3044
  /**
3143
3045
  * Skip ffmpeg process when possible
3144
3046
  */
@@ -3329,6 +3231,67 @@ declare class QueryResolver {
3329
3231
  static validateURL(q: string): boolean;
3330
3232
  }
3331
3233
 
3234
+ interface PackageJSON {
3235
+ name: string;
3236
+ version: string;
3237
+ }
3238
+ type MaybeNull<T> = T | null;
3239
+ interface DependenciesReport {
3240
+ core: {
3241
+ 'discord-player': string;
3242
+ 'discord-voip': string;
3243
+ };
3244
+ libopus: {
3245
+ mediaplex: MaybeNull<string>;
3246
+ '@discordjs/opus': MaybeNull<string>;
3247
+ '@evan/opus': MaybeNull<string>;
3248
+ opusscript: MaybeNull<string>;
3249
+ 'node-opus': MaybeNull<string>;
3250
+ };
3251
+ libsodium: {
3252
+ 'sodium-native': MaybeNull<string>;
3253
+ sodium: MaybeNull<string>;
3254
+ 'libsodium-wrappers': MaybeNull<string>;
3255
+ 'sodium-javascript': MaybeNull<string>;
3256
+ '@stablelib/xchacha20poly1305': MaybeNull<string>;
3257
+ };
3258
+ ffmpeg: FFmpegReport;
3259
+ }
3260
+ type FFmpegReport = Record<FFmpegLib, MaybeNull<{
3261
+ version: string;
3262
+ hasLibopus: boolean;
3263
+ }>>;
3264
+ /**
3265
+ * A utility to generate a report of the dependencies used by the discord-player module.
3266
+ */
3267
+ declare const DependencyReportGenerator: {
3268
+ /**
3269
+ * Finds the package.json file of a package.
3270
+ * @param dir - The directory to start searching from
3271
+ * @param packageName - The name of the package to find
3272
+ * @param depth - The maximum depth to search
3273
+ * @returns The package.json file, or null if not found
3274
+ */
3275
+ findPackageJSON(dir: string, packageName: string, depth: number): PackageJSON | null;
3276
+ /**
3277
+ * Tries to find the version of a dependency.
3278
+ * @param name - The package to find the version of
3279
+ * @param maxLookupDepth - The maximum depth to search for the package.json file
3280
+ * @returns The version of the package, or null if not found
3281
+ */
3282
+ version(name: string, maxLookupDepth?: number): string | null;
3283
+ /**
3284
+ * Generates a report of the dependencies used by the discord-player module.
3285
+ * @returns The report object
3286
+ */
3287
+ generate(): DependenciesReport;
3288
+ /**
3289
+ * Generates a string representation of the dependencies report.
3290
+ * @returns The string representation
3291
+ */
3292
+ generateString(): string;
3293
+ };
3294
+
3332
3295
  declare const version: string;
3333
3296
 
3334
- export { AFilterGraph, AsyncQueue, AsyncQueueAcquisitionOptions, AsyncQueueEntry, AsyncQueueExceptionHandler, AudioFilters, BaseExtractor, Context, ContextReceiver, CreateStreamOps, DiscordPlayerQueryResultCache, Encodable, EqualizerConfigurationPreset, ExtractorExecutionContext, ExtractorExecutionEvents, ExtractorExecutionFN, ExtractorExecutionResult, ExtractorInfo, ExtractorLoaderOptionDict, ExtractorResolvable, ExtractorSearchContext, ExtractorSession, ExtractorStreamable, FFMPEG_ARGS_PIPED, FFMPEG_ARGS_STRING, FFMPEG_SRATE_REGEX, FFmpegFilterer, FFmpegStreamOptions, FilterGraph, FiltersName, GuildNodeCreateOptions, GuildNodeInit, GuildNodeManager, GuildQueue, GuildQueueAFiltersCache, GuildQueueAudioFilters, GuildQueueEvent, GuildQueueEvents, GuildQueueHistory, GuildQueuePlayerNode, GuildQueueStatistics, GuildQueueStatisticsMetadata, HookDeclaration, HookDeclarationContext, IPBlock, IPRotationConfig, IPRotator, LrcGetParams, LrcGetResult, LrcLib, LrcSearchParams, LrcSearchResult, MetadataDispatch, NextFunction, NodeResolvable, OnAfterCreateStreamHandler, OnBeforeCreateStreamHandler, PlayOptions, Player, PlayerEvent, PlayerEvents, PlayerEventsEmitter, PlayerInitOptions, PlayerNodeInitializationResult, PlayerNodeInitializerOptions, PlayerProgressbarOptions, PlayerSearchResult, PlayerTimestamp, PlayerTriggeredReason, Playlist, PlaylistInitData, PlaylistJSON, PostProcessedResult, QueryCache, QueryCacheOptions, QueryCacheProvider, QueryCacheResolverContext, QueryExtractorSearch, QueryResolver, QueryType, QueueFilters, QueueRepeatMode, RawTrackData, RequestEntity, ResolvedQuery, ResourcePlayOptions, Runtime, RuntimeType, SearchOptions, SearchQueryType, SearchResult, SearchResultData, SequentialBucket, SerializedPlaylist, SerializedTrack, SerializedType, SetterFN$1 as SetterFN, SkipOptions, StreamConfig, StreamDispatcher, TimeData, TimelineDispatcherOptions, Track, TrackJSON, TrackLike, TrackResolvable, TrackSkipReason, TrackSource, TypeUtil, Util, VALIDATE_QUEUE_CAP, VoiceConnectConfig, VoiceEvents, VoiceStateHandler, VoiceUtils, WithMetadata, createContext, createErisCompat, createFFmpegStream, createHook, decode, deserialize, encode, isErisProxy, onAfterCreateStream, onBeforeCreateStream, serialize, tryIntoThumbnailString, useContext, useHistory, useMainPlayer, useMasterPlayer, useMetadata, usePlayer, useQueue, useTimeline, useVolume, version };
3297
+ export { AFilterGraph, AsyncQueue, AsyncQueueAcquisitionOptions, AsyncQueueEntry, AsyncQueueExceptionHandler, AudioFilters, BaseExtractor, Context, ContextReceiver, CreateStreamOps, DependenciesReport, DependencyReportGenerator, DiscordPlayerQueryResultCache, Encodable, EqualizerConfigurationPreset, ExtractorExecutionContext, ExtractorExecutionEvents, ExtractorExecutionFN, ExtractorExecutionResult, ExtractorInfo, ExtractorLoaderOptionDict, ExtractorResolvable, ExtractorSearchContext, ExtractorSession, ExtractorStreamable, FFMPEG_ARGS_PIPED, FFMPEG_ARGS_STRING, FFMPEG_SRATE_REGEX, FFmpegFilterer, FFmpegReport, FFmpegStreamOptions, FilterGraph, FiltersName, GuildNodeCreateOptions, GuildNodeInit, GuildNodeManager, GuildQueue, GuildQueueAFiltersCache, GuildQueueAudioFilters, GuildQueueEvent, GuildQueueEvents, GuildQueueHistory, GuildQueuePlayerNode, GuildQueueStatistics, GuildQueueStatisticsMetadata, LrcGetParams, LrcGetResult, LrcLib, LrcSearchParams, LrcSearchResult, MaybeNull, MetadataDispatch, NextFunction, NodeResolvable, OnAfterCreateStreamHandler, OnBeforeCreateStreamHandler, PackageJSON, PlayOptions, Player, PlayerEvent, PlayerEvents, PlayerEventsEmitter, PlayerInitOptions, PlayerNodeInitializationResult, PlayerNodeInitializerOptions, PlayerProgressbarOptions, PlayerSearchResult, PlayerTimestamp, PlayerTriggeredReason, Playlist, PlaylistInitData, PlaylistJSON, PostProcessedResult, QueryCache, QueryCacheOptions, QueryCacheProvider, QueryCacheResolverContext, QueryExtractorSearch, QueryResolver, QueryType, QueueFilters, QueueRepeatMode, RawTrackData, RequestEntity, ResolvedQuery, ResourcePlayOptions, Runtime, RuntimeType, SearchOptions, SearchQueryType, SearchResult, SearchResultData, SequentialBucket, SerializedPlaylist, SerializedTrack, SerializedType, SetterFN$1 as SetterFN, SkipOptions, StreamConfig, StreamDispatcher, TimeData, TimelineDispatcherOptions, Track, TrackJSON, TrackLike, TrackResolvable, TrackSkipReason, TrackSource, TypeUtil, Util, VALIDATE_QUEUE_CAP, VoiceConnectConfig, VoiceEvents, VoiceStateHandler, VoiceUtils, WithMetadata, createContext, createErisCompat, createFFmpegStream, decode, deserialize, encode, isErisProxy, onAfterCreateStream, onBeforeCreateStream, serialize, tryIntoThumbnailString, useContext, useHistory, useMainPlayer, useMetadata, usePlayer, useQueue, useTimeline, useVolume, version };