discord-player 6.6.3-dev.0 → 6.6.3
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 +34 -18
- package/dist/index.d.ts +50 -2
- package/dist/index.js +138 -13
- package/dist/index.mjs +4 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -41,17 +41,33 @@ $ npm install --save @discord-player/extractor # extractors provider
|
|
|
41
41
|
|
|
42
42
|
#### Opus Library
|
|
43
43
|
|
|
44
|
-
Since Discord only accepts opus packets, you need to install the opus library.
|
|
44
|
+
Since Discord only accepts opus packets, you need to install the opus library. Discord Player supports multiple opus libraries, such as:
|
|
45
|
+
|
|
46
|
+
- [mediaplex](https://npmjs.com/mediaplex)
|
|
47
|
+
- [@discordjs/opus](https://npmjs.com/@discordjs/opus)
|
|
48
|
+
- [opusscript](https://npmjs.com/opusscript)
|
|
49
|
+
- [@evan/opus](https://npmjs.com/@evan/opus)
|
|
50
|
+
- [node-opus](https://npmjs.com/node-opus)
|
|
51
|
+
|
|
52
|
+
Among these, mediaplex is the recommended library as it adds more functionalities to discord-player than just libopus interface. You can install opus libraries by running:
|
|
45
53
|
|
|
46
54
|
```bash
|
|
55
|
+
$ npm install --save mediaplex
|
|
56
|
+
# or
|
|
47
57
|
$ npm install --save @discordjs/opus
|
|
48
58
|
# or
|
|
49
59
|
$ npm install --save opusscript
|
|
60
|
+
# or
|
|
61
|
+
$ npm install --save @evan/opus
|
|
62
|
+
# or
|
|
63
|
+
$ npm install --save node-opus
|
|
50
64
|
```
|
|
51
65
|
|
|
52
66
|
#### FFmpeg or Avconv
|
|
53
67
|
|
|
54
|
-
FFmpeg or Avconv is required for media transcoding. You can obtain it from [https://ffmpeg.org](https://ffmpeg.org) or
|
|
68
|
+
FFmpeg or Avconv is required for media transcoding. You can obtain it from [https://ffmpeg.org](https://ffmpeg.org) or via npm.
|
|
69
|
+
|
|
70
|
+
> We do not recommend installing ffmpeg via npm because binaries pulled from npm is known to be unstable. It is recommended to install it from the official source.
|
|
55
71
|
|
|
56
72
|
```bash
|
|
57
73
|
$ npm install --save ffmpeg-static
|
|
@@ -67,30 +83,31 @@ $ npm install --save ffmpeg-binaries
|
|
|
67
83
|
|
|
68
84
|
#### Streaming Library
|
|
69
85
|
|
|
70
|
-
If you want to add support for YouTube playback, you need to install a streaming library.
|
|
86
|
+
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.
|
|
71
87
|
|
|
72
88
|
```bash
|
|
73
|
-
$ npm install --save
|
|
89
|
+
$ npm install --save youtube-ext
|
|
74
90
|
# or
|
|
75
91
|
$ npm install --save play-dl
|
|
76
92
|
# or
|
|
77
93
|
$ npm install --save @distube/ytdl-core
|
|
78
94
|
# or
|
|
79
95
|
$ npm install --save yt-stream
|
|
96
|
+
# or
|
|
97
|
+
$ npm install --save ytdl-core
|
|
80
98
|
```
|
|
81
99
|
|
|
100
|
+
We recommend using `youtube-ext` for better performance.
|
|
101
|
+
|
|
82
102
|
Once you have completed these installations, let's proceed with writing a simple music bot.
|
|
83
103
|
|
|
84
104
|
### Setup
|
|
85
105
|
|
|
86
106
|
Let's create a main player instance. This instance handles and keeps track of all the queues and its components.
|
|
87
107
|
|
|
88
|
-
```js
|
|
108
|
+
```js index.js
|
|
89
109
|
const { Player } = require('discord-player');
|
|
90
110
|
|
|
91
|
-
// get some extractors if you want to handpick sources
|
|
92
|
-
const { SpotifyExtractor, SoundCloudExtractor } = require('@discord-player/extractor');
|
|
93
|
-
|
|
94
111
|
const client = new Discord.Client({
|
|
95
112
|
// Make sure you have 'GuildVoiceStates' intent enabled
|
|
96
113
|
intents: ['GuildVoiceStates' /* Other intents */]
|
|
@@ -99,17 +116,13 @@ const client = new Discord.Client({
|
|
|
99
116
|
// this is the entrypoint for discord-player based application
|
|
100
117
|
const player = new Player(client);
|
|
101
118
|
|
|
102
|
-
//
|
|
103
|
-
await player.extractors.loadDefault();
|
|
104
|
-
|
|
105
|
-
// If you dont want to use all of the extractors and register only the required ones manually, use
|
|
106
|
-
await player.extractors.register(SpotifyExtractor, {});
|
|
107
|
-
await player.extractors.register(SoundCloudExtractor, {});
|
|
119
|
+
// Now, lets load all the default extractors, except 'YouTubeExtractor'. You can remove the filter if you want to load all the extractors.
|
|
120
|
+
await player.extractors.loadDefault((ext) => ext !== 'YouTubeExtractor');
|
|
108
121
|
```
|
|
109
122
|
|
|
110
123
|
Discord Player is mostly events based. It emits different events based on the context and actions. Let's add a basic event listener to notify the user when a track starts to play:
|
|
111
124
|
|
|
112
|
-
```js
|
|
125
|
+
```js index.js
|
|
113
126
|
// this event is emitted whenever discord-player starts to play a track
|
|
114
127
|
player.events.on('playerStart', (queue, track) => {
|
|
115
128
|
// we will later define queue.metadata object while creating the queue
|
|
@@ -117,10 +130,13 @@ player.events.on('playerStart', (queue, track) => {
|
|
|
117
130
|
});
|
|
118
131
|
```
|
|
119
132
|
|
|
120
|
-
Let's move on to the command part. You can define the command as per your requirements. We will only focus on the command
|
|
133
|
+
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:
|
|
134
|
+
|
|
135
|
+
```js play.js
|
|
136
|
+
const { useMainPlayer } = require('discord-player');
|
|
121
137
|
|
|
122
|
-
|
|
123
|
-
|
|
138
|
+
export async function execute(interaction) {
|
|
139
|
+
const player = useMainPlayer();
|
|
124
140
|
const channel = interaction.member.voice.channel;
|
|
125
141
|
if (!channel) return interaction.reply('You are not connected to a voice channel!'); // make sure we have a voice channel
|
|
126
142
|
const query = interaction.options.getString('query', true); // we need input/query to play
|
package/dist/index.d.ts
CHANGED
|
@@ -1535,7 +1535,7 @@ declare class BaseExtractor<T extends object = object> {
|
|
|
1535
1535
|
* Get related tracks for the given track
|
|
1536
1536
|
* @param track The track source
|
|
1537
1537
|
*/
|
|
1538
|
-
getRelatedTracks(track: Track): Promise<ExtractorInfo>;
|
|
1538
|
+
getRelatedTracks(track: Track, history: GuildQueueHistory): Promise<ExtractorInfo>;
|
|
1539
1539
|
/**
|
|
1540
1540
|
* A stream middleware to handle streams before passing it to the player
|
|
1541
1541
|
* @param stream The incoming stream
|
|
@@ -1559,6 +1559,10 @@ declare class BaseExtractor<T extends object = object> {
|
|
|
1559
1559
|
* @param message The debug message
|
|
1560
1560
|
*/
|
|
1561
1561
|
debug(message: string): boolean;
|
|
1562
|
+
/**
|
|
1563
|
+
* IP rotator instance, if available
|
|
1564
|
+
*/
|
|
1565
|
+
get routePlanner(): IPRotator | null;
|
|
1562
1566
|
}
|
|
1563
1567
|
type NextFunction = (error?: Error | null, stream?: Readable) => void;
|
|
1564
1568
|
interface ExtractorInfo {
|
|
@@ -1726,6 +1730,44 @@ declare class VoiceUtils {
|
|
|
1726
1730
|
getConnection(guild: Snowflake, group?: string): VoiceConnection | undefined;
|
|
1727
1731
|
}
|
|
1728
1732
|
|
|
1733
|
+
declare class IPBlock {
|
|
1734
|
+
block: string;
|
|
1735
|
+
usage: number;
|
|
1736
|
+
readonly cidr: string;
|
|
1737
|
+
readonly cidrSize: number;
|
|
1738
|
+
constructor(block: string);
|
|
1739
|
+
consume(): void;
|
|
1740
|
+
}
|
|
1741
|
+
interface IPRotationConfig {
|
|
1742
|
+
/**
|
|
1743
|
+
* IP blocks to use
|
|
1744
|
+
*/
|
|
1745
|
+
blocks: string[];
|
|
1746
|
+
/**
|
|
1747
|
+
* IPs to exclude
|
|
1748
|
+
*/
|
|
1749
|
+
exclude?: string[];
|
|
1750
|
+
/**
|
|
1751
|
+
* Max retries to find an IP that is not excluded
|
|
1752
|
+
*/
|
|
1753
|
+
maxRetries?: number;
|
|
1754
|
+
}
|
|
1755
|
+
declare class IPRotator {
|
|
1756
|
+
#private;
|
|
1757
|
+
config: IPRotationConfig;
|
|
1758
|
+
blocks: IPBlock[];
|
|
1759
|
+
failures: Map<string, number>;
|
|
1760
|
+
MAX_NEXT_RETRIES: number;
|
|
1761
|
+
constructor(config: IPRotationConfig);
|
|
1762
|
+
getIP(): {
|
|
1763
|
+
ip: string;
|
|
1764
|
+
family: 4 | 6;
|
|
1765
|
+
};
|
|
1766
|
+
isFailedOrExcluded(ip: string): boolean;
|
|
1767
|
+
addFailed(ip: string): void;
|
|
1768
|
+
static getRandomIP(address: string, start?: number, end?: number): string;
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1729
1771
|
interface PlayerNodeInitializationResult<T = unknown> {
|
|
1730
1772
|
track: Track;
|
|
1731
1773
|
extractor: BaseExtractor | null;
|
|
@@ -1752,6 +1794,7 @@ declare class Player extends PlayerEventsEmitter<PlayerEvents> {
|
|
|
1752
1794
|
readonly voiceUtils: VoiceUtils;
|
|
1753
1795
|
extractors: ExtractorExecutionContext;
|
|
1754
1796
|
events: PlayerEventsEmitter<GuildQueueEvents<any>>;
|
|
1797
|
+
routePlanner: IPRotator | null;
|
|
1755
1798
|
/**
|
|
1756
1799
|
* Creates new Discord Player
|
|
1757
1800
|
* @param {Client} client The Discord Client
|
|
@@ -2020,6 +2063,7 @@ interface QueueFilters {
|
|
|
2020
2063
|
dim?: boolean;
|
|
2021
2064
|
earrape?: boolean;
|
|
2022
2065
|
lofi?: boolean;
|
|
2066
|
+
silenceremove?: boolean;
|
|
2023
2067
|
}
|
|
2024
2068
|
/**
|
|
2025
2069
|
* The track source:
|
|
@@ -2180,12 +2224,14 @@ type QueryExtractorSearch = `ext:${string}`;
|
|
|
2180
2224
|
* @property {string[]} [blockExtractors[]] List of the extractors to block
|
|
2181
2225
|
* @property {boolean} [ignoreCache] If it should ignore query cache lookup
|
|
2182
2226
|
* @property {SearchQueryType} [fallbackSearchEngine='autoSearch'] Fallback search engine to use
|
|
2227
|
+
* @property {any} [requestOptions] The request options
|
|
2183
2228
|
*/
|
|
2184
2229
|
interface SearchOptions {
|
|
2185
2230
|
requestedBy?: UserResolvable;
|
|
2186
2231
|
searchEngine?: SearchQueryType | QueryExtractorSearch;
|
|
2187
2232
|
blockExtractors?: string[];
|
|
2188
2233
|
ignoreCache?: boolean;
|
|
2234
|
+
requestOptions?: any;
|
|
2189
2235
|
fallbackSearchEngine?: (typeof QueryType)[keyof typeof QueryType];
|
|
2190
2236
|
}
|
|
2191
2237
|
/**
|
|
@@ -2298,6 +2344,7 @@ interface PlaylistJSON {
|
|
|
2298
2344
|
* @property {boolean} [ignoreInstance] Ignore player instance
|
|
2299
2345
|
* @property {boolean} [useLegacyFFmpeg] Use legacy version of ffmpeg
|
|
2300
2346
|
* @property {BridgeProvider} [bridgeProvider] Set bridge provider
|
|
2347
|
+
* @property {object} [ipconfig] IP rotator config
|
|
2301
2348
|
*/
|
|
2302
2349
|
interface PlayerInitOptions {
|
|
2303
2350
|
ytdlOptions?: downloadOptions;
|
|
@@ -2310,6 +2357,7 @@ interface PlayerInitOptions {
|
|
|
2310
2357
|
ignoreInstance?: boolean;
|
|
2311
2358
|
useLegacyFFmpeg?: boolean;
|
|
2312
2359
|
bridgeProvider?: BridgeProvider;
|
|
2360
|
+
ipconfig?: IPRotationConfig;
|
|
2313
2361
|
}
|
|
2314
2362
|
|
|
2315
2363
|
declare class AudioFilters {
|
|
@@ -2549,4 +2597,4 @@ declare function createHook<T extends HookDeclaration<(...args: any[]) => any>>(
|
|
|
2549
2597
|
|
|
2550
2598
|
declare const version: string;
|
|
2551
2599
|
|
|
2552
|
-
export { AFilterGraph, AsyncQueue, AsyncQueueAcquisitionOptions, AsyncQueueEntry, AsyncQueueExceptionHandler, AudioFilters, BaseExtractor, CreateStreamOps, DiscordPlayerQueryResultCache, EqualizerConfigurationPreset, ExtractorExecutionContext, ExtractorExecutionEvents, ExtractorExecutionFN, ExtractorExecutionResult, ExtractorInfo, ExtractorSearchContext, 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, 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, RawTrackInit, ResolvedQuery, ResourcePlayOptions, SearchOptions, SearchQueryType, SearchResult, SearchResultData, StreamConfig, StreamDispatcher, TimeData, TimelineDispatcherOptions, Track, TrackJSON, TrackLike, TrackResolvable, TrackSource, TypeUtil, Util, VALIDATE_QUEUE_CAP, VoiceConnectConfig, VoiceEvents, VoiceReceiverNode, VoiceReceiverOptions, VoiceStateHandler, VoiceUtils, WithMetadata, createFFmpegStream, createHook, onAfterCreateStream, onBeforeCreateStream, useHistory, useMainPlayer, useMasterPlayer, useMetadata, usePlayer, useQueue, useTimeline, useVolume, version };
|
|
2600
|
+
export { AFilterGraph, AsyncQueue, AsyncQueueAcquisitionOptions, AsyncQueueEntry, AsyncQueueExceptionHandler, AudioFilters, BaseExtractor, CreateStreamOps, DiscordPlayerQueryResultCache, EqualizerConfigurationPreset, ExtractorExecutionContext, ExtractorExecutionEvents, ExtractorExecutionFN, ExtractorExecutionResult, ExtractorInfo, ExtractorSearchContext, 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, 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, RawTrackInit, ResolvedQuery, ResourcePlayOptions, SearchOptions, SearchQueryType, SearchResult, SearchResultData, StreamConfig, StreamDispatcher, TimeData, TimelineDispatcherOptions, Track, TrackJSON, TrackLike, TrackResolvable, TrackSource, TypeUtil, Util, VALIDATE_QUEUE_CAP, VoiceConnectConfig, VoiceEvents, VoiceReceiverNode, VoiceReceiverOptions, VoiceStateHandler, VoiceUtils, WithMetadata, createFFmpegStream, createHook, onAfterCreateStream, onBeforeCreateStream, useHistory, useMainPlayer, useMasterPlayer, useMetadata, usePlayer, useQueue, useTimeline, useVolume, version };
|