discord-player 7.0.0-dev.3 → 7.0.0-dev.5

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
@@ -8,26 +8,24 @@ Discord Player is a robust framework for developing Discord Music bots using Jav
8
8
 
9
9
  # Why Choose Discord Player?
10
10
 
11
- - Beginner-friendly with easy-to-understand features
12
- - TypeScript support
13
- - Offers hackable APIs.
14
- - Supports audio player sharing
15
- - Quick and easy setup process
16
- - Wide range of player management features
17
- - Offers 64+ built-in audio filter presets
18
- - Highly customizable according to your needs
19
- - Automatic queue management
20
- - Query caching support
21
- - Extensible sources through the Extractors API
22
- - Object-oriented design
23
- - Built-in stats tracker
24
- - Offers easy debugging methods
25
- - Out-of-the-box voice states handling
26
- - IP Rotation support
27
- - Easy serialization and deserialization
28
- - Limited support for [Eris](https://npmjs.com/eris)
29
-
30
- > Eris compat mode does not support `VoiceStateUpdate` handler. You need to handle it manually.
11
+ - Beginner-friendly with easy-to-understand features
12
+ - TypeScript support
13
+ - Offers hackable APIs.
14
+ - Supports audio player sharing
15
+ - Quick and easy setup process
16
+ - Wide range of player management features
17
+ - Offers 64+ built-in audio filter presets
18
+ - Highly customizable according to your needs
19
+ - Automatic queue management
20
+ - Query caching support
21
+ - Extensible sources through the Extractors API
22
+ - Object-oriented design
23
+ - Built-in stats tracker
24
+ - Offers easy debugging methods
25
+ - Out-of-the-box voice states handling
26
+ - IP Rotation support
27
+ - Easy serialization and deserialization
28
+ - Limited support for [Eris](https://npmjs.com/eris)
31
29
 
32
30
  ## Installation
33
31
 
@@ -42,30 +40,12 @@ $ npm install --save discord-player # main library
42
40
  $ npm install --save @discord-player/extractor # extractors provider
43
41
  ```
44
42
 
45
- > Discord Player recognizes `@discord-player/extractor` and loads it automatically by default. Just invoke `await player.extractors.loadDefault()`.
46
-
47
43
  #### Opus Library
48
44
 
49
- Since Discord only accepts opus packets, you need to install the opus library. Discord Player supports multiple opus libraries, such as:
50
-
51
- - [mediaplex](https://npmjs.com/mediaplex)
52
- - [@discordjs/opus](https://npmjs.com/@discordjs/opus)
53
- - [opusscript](https://npmjs.com/opusscript)
54
- - [@evan/opus](https://npmjs.com/@evan/opus)
55
- - [node-opus](https://npmjs.com/node-opus)
56
-
57
- 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
+ We recommend mediaplex for libopus. Mediaplex also helps with audio metadata extraction.
58
46
 
59
47
  ```bash
60
48
  $ npm install --save mediaplex
61
- # or
62
- $ npm install --save @discordjs/opus
63
- # or
64
- $ npm install --save opusscript
65
- # or
66
- $ npm install --save @evan/opus
67
- # or
68
- $ npm install --save node-opus
69
49
  ```
70
50
 
71
51
  #### FFmpeg or Avconv
@@ -92,17 +72,18 @@ Let's create a main player instance. This instance handles and keeps track of al
92
72
 
93
73
  ```js index.js
94
74
  const { Player } = require('discord-player');
75
+ const { DefaultExtractors } = require('@discord-player/extractor');
95
76
 
96
77
  const client = new Discord.Client({
97
- // Make sure you have 'GuildVoiceStates' intent enabled
98
- intents: ['GuildVoiceStates' /* Other intents */]
78
+ // Make sure you have 'GuildVoiceStates' intent enabled
79
+ intents: ['GuildVoiceStates' /* Other intents */],
99
80
  });
100
81
 
101
82
  // this is the entrypoint for discord-player based application
102
83
  const player = new Player(client);
103
84
 
104
85
  // Now, lets load all the default extractors, except 'YouTubeExtractor'. You can remove the filter if you want to include youtube.
105
- await player.extractors.loadDefault((ext) => ext !== 'YouTubeExtractor');
86
+ await player.extractors.loadMulti(DefaultExtractors);
106
87
  ```
107
88
 
108
89
  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:
@@ -110,8 +91,8 @@ Discord Player is mostly events based. It emits different events based on the co
110
91
  ```js index.js
111
92
  // this event is emitted whenever discord-player starts to play a track
112
93
  player.events.on('playerStart', (queue, track) => {
113
- // we will later define queue.metadata object while creating the queue
114
- queue.metadata.channel.send(`Started playing **${track.cleanTitle}**!`);
94
+ // we will later define queue.metadata object while creating the queue
95
+ queue.metadata.channel.send(`Started playing **${track.cleanTitle}**!`);
115
96
  });
116
97
  ```
117
98
 
@@ -149,27 +130,27 @@ Let's move on to the command part. You can define the command as per your requir
149
130
  const { useMainPlayer } = require('discord-player');
150
131
 
151
132
  export async function execute(interaction) {
152
- const player = useMainPlayer(); // get player instance
153
- const channel = interaction.member.voice.channel;
154
- if (!channel) return interaction.reply('You are not connected to a voice channel!'); // make sure we have a voice channel
155
- const query = interaction.options.getString('query', true); // we need input/query to play
156
-
157
- // let's defer the interaction as things can take time to process
158
- await interaction.deferReply();
159
-
160
- try {
161
- const { track } = await player.play(channel, query, {
162
- nodeOptions: {
163
- // nodeOptions are the options for guild node (aka your queue in simple word)
164
- metadata: interaction // we can access this metadata object using queue.metadata later on
165
- }
166
- });
167
-
168
- return interaction.followUp(`**${track.cleanTitle}** enqueued!`);
169
- } catch (e) {
170
- // let's return error if something failed
171
- return interaction.followUp(`Something went wrong: ${e}`);
172
- }
133
+ const player = useMainPlayer(); // get player instance
134
+ const channel = interaction.member.voice.channel;
135
+ if (!channel) return interaction.reply('You are not connected to a voice channel!'); // make sure we have a voice channel
136
+ const query = interaction.options.getString('query', true); // we need input/query to play
137
+
138
+ // let's defer the interaction as things can take time to process
139
+ await interaction.deferReply();
140
+
141
+ try {
142
+ const { track } = await player.play(channel, query, {
143
+ nodeOptions: {
144
+ // nodeOptions are the options for guild node (aka your queue in simple word)
145
+ metadata: interaction, // we can access this metadata object using queue.metadata later on
146
+ },
147
+ });
148
+
149
+ return interaction.followUp(`**${track.cleanTitle}** enqueued!`);
150
+ } catch (e) {
151
+ // let's return error if something failed
152
+ return interaction.followUp(`Something went wrong: ${e}`);
153
+ }
173
154
  }
174
155
  ```
175
156
 
package/dist/index.d.ts CHANGED
@@ -953,147 +953,118 @@ declare const GuildQueueEvent: {
953
953
  /**
954
954
  * Emitted when audio track is added to the queue
955
955
  */
956
- readonly audioTrackAdd: "audioTrackAdd";
957
956
  readonly AudioTrackAdd: "audioTrackAdd";
958
957
  /**
959
958
  * Emitted when audio tracks were added to the queue
960
959
  */
961
- readonly audioTracksAdd: "audioTracksAdd";
962
960
  readonly AudioTracksAdd: "audioTracksAdd";
963
961
  /**
964
962
  * Emitted when audio track is removed from the queue
965
963
  */
966
- readonly audioTrackRemove: "audioTrackRemove";
967
964
  readonly AudioTrackRemove: "audioTrackRemove";
968
965
  /**
969
966
  * Emitted when audio tracks are removed from the queue
970
967
  */
971
- readonly audioTracksRemove: "audioTracksRemove";
972
968
  readonly AudioTracksRemove: "audioTracksRemove";
973
969
  /**
974
970
  * Emitted when a connection is created
975
971
  */
976
- readonly connection: "connection";
977
972
  readonly Connection: "connection";
978
973
  /**
979
974
  * Emitted when a voice connection is destroyed
980
975
  */
981
- readonly connectionDestroyed: "connectionDestroyed";
982
976
  readonly ConnectionDestroyed: "connectionDestroyed";
983
977
  /**
984
978
  * Emitted when the bot is disconnected from the channel
985
979
  */
986
- readonly disconnect: "disconnect";
987
980
  readonly Disconnect: "disconnect";
988
981
  /**
989
982
  * Emitted when the queue sends a debug info
990
983
  */
991
- readonly debug: "debug";
992
984
  readonly Debug: "debug";
993
985
  /**
994
986
  * Emitted when the queue encounters error
995
987
  */
996
- readonly error: "error";
997
988
  readonly Error: "error";
998
989
  /**
999
990
  * Emitted when the voice channel is empty
1000
991
  */
1001
- readonly emptyChannel: "emptyChannel";
1002
992
  readonly EmptyChannel: "emptyChannel";
1003
993
  /**
1004
994
  * Emitted when the queue is empty
1005
995
  */
1006
- readonly emptyQueue: "emptyQueue";
1007
996
  readonly EmptyQueue: "emptyQueue";
1008
997
  /**
1009
998
  * Emitted when the audio player starts streaming audio track
1010
999
  */
1011
- readonly playerStart: "playerStart";
1012
1000
  readonly PlayerStart: "playerStart";
1013
1001
  /**
1014
1002
  * Emitted when the audio player errors while streaming audio track
1015
1003
  */
1016
- readonly playerError: "playerError";
1017
1004
  readonly PlayerError: "playerError";
1018
1005
  /**
1019
1006
  * Emitted when the audio player finishes streaming audio track
1020
1007
  */
1021
- readonly playerFinish: "playerFinish";
1022
1008
  readonly PlayerFinish: "playerFinish";
1023
1009
  /**
1024
1010
  * Emitted when the audio player skips current track
1025
1011
  */
1026
- readonly playerSkip: "playerSkip";
1027
1012
  readonly PlayerSkip: "playerSkip";
1028
1013
  /**
1029
1014
  * Emitted when the audio player is triggered
1030
1015
  */
1031
- readonly playerTrigger: "playerTrigger";
1032
1016
  readonly PlayerTrigger: "playerTrigger";
1033
1017
  /**
1034
1018
  * Emitted when the voice state is updated. Consuming this event may disable default voice state update handler if `Player.isVoiceStateHandlerLocked()` returns `false`.
1035
1019
  */
1036
- readonly voiceStateUpdate: "voiceStateUpdate";
1037
1020
  readonly VoiceStateUpdate: "voiceStateUpdate";
1038
1021
  /**
1039
1022
  * Emitted when volume is updated
1040
1023
  */
1041
- readonly volumeChange: "volumeChange";
1042
1024
  readonly VolumeChange: "volumeChange";
1043
1025
  /**
1044
1026
  * Emitted when player is paused
1045
1027
  */
1046
- readonly playerPause: "playerPause";
1047
1028
  readonly PlayerPause: "playerPause";
1048
1029
  /**
1049
1030
  * Emitted when player is resumed
1050
1031
  */
1051
- readonly playerResume: "playerResume";
1052
1032
  readonly PlayerResume: "playerResume";
1053
1033
  /**
1054
1034
  * Biquad Filters Update
1055
1035
  */
1056
- readonly biquadFiltersUpdate: "biquadFiltersUpdate";
1057
1036
  readonly BiquadFiltersUpdate: "biquadFiltersUpdate";
1058
1037
  /**
1059
1038
  * Equalizer Update
1060
1039
  */
1061
- readonly equalizerUpdate: "equalizerUpdate";
1062
1040
  readonly EqualizerUpdate: "equalizerUpdate";
1063
1041
  /**
1064
1042
  * DSP update
1065
1043
  */
1066
- readonly dspUpdate: "dspUpdate";
1067
1044
  readonly DSPUpdate: "dspUpdate";
1068
1045
  /**
1069
1046
  * Audio Filters Update
1070
1047
  */
1071
- readonly audioFiltersUpdate: "audioFiltersUpdate";
1072
1048
  readonly AudioFiltersUpdate: "audioFiltersUpdate";
1073
1049
  /**
1074
1050
  * Audio player will play next track
1075
1051
  */
1076
- readonly willPlayTrack: "willPlayTrack";
1077
1052
  readonly WillPlayTrack: "willPlayTrack";
1078
1053
  /**
1079
1054
  * Emitted when a voice channel is repopulated
1080
1055
  */
1081
- readonly channelPopulate: "channelPopulate";
1082
1056
  readonly ChannelPopulate: "channelPopulate";
1083
1057
  /**
1084
1058
  * Emitted when a queue is successfully created
1085
1059
  */
1086
- readonly queueCreate: "queueCreate";
1087
1060
  readonly QueueCreate: "queueCreate";
1088
1061
  /**
1089
1062
  * Emitted when a queue is deleted
1090
1063
  */
1091
- readonly queueDelete: "queueDelete";
1092
1064
  readonly QueueDelete: "queueDelete";
1093
1065
  /**
1094
1066
  * Emitted when a queue is trying to add similar track for autoplay
1095
1067
  */
1096
- readonly willAutoPlay: "willAutoPlay";
1097
1068
  readonly WillAutoPlay: "willAutoPlay";
1098
1069
  };
1099
1070
  type GuildQueueEvent = (typeof GuildQueueEvent)[keyof typeof GuildQueueEvent];
@@ -1806,18 +1777,21 @@ declare function useContext<T = unsafe>(context: Context<T>): T | undefined;
1806
1777
  * @param node guild queue node resolvable
1807
1778
  */
1808
1779
  declare function useHistory<Meta = unknown>(): GuildQueueHistory<Meta> | null;
1780
+ declare function useHistory<Meta = unknown>(node: NodeResolvable): GuildQueueHistory<Meta> | null;
1809
1781
 
1810
1782
  /**
1811
1783
  * Fetch guild queue player node
1812
1784
  * @param node Guild queue node resolvable
1813
1785
  */
1814
1786
  declare function usePlayer<Meta = unknown>(): GuildQueuePlayerNode<Meta> | null;
1787
+ declare function usePlayer<Meta = unknown>(node: NodeResolvable): GuildQueuePlayerNode<Meta> | null;
1815
1788
 
1816
1789
  /**
1817
1790
  * Fetch guild queue.
1818
1791
  * @param node Guild queue node resolvable. Defaults to inferred guild from context.
1819
1792
  */
1820
1793
  declare function useQueue<Meta = unknown>(): GuildQueue<Meta> | null;
1794
+ declare function useQueue<Meta = unknown>(node: NodeResolvable): GuildQueue<Meta> | null;
1821
1795
 
1822
1796
  /**
1823
1797
  * Fetch main player instance
@@ -1831,6 +1805,7 @@ type MetadataDispatch<T> = readonly [() => T, (metadata: T | SetterFN$1<T, T>) =
1831
1805
  * @param node Guild queue node resolvable
1832
1806
  */
1833
1807
  declare function useMetadata<T = unknown>(): MetadataDispatch<T>;
1808
+ declare function useMetadata<T = unknown>(node: NodeResolvable): MetadataDispatch<T>;
1834
1809
 
1835
1810
  interface TimelineDispatcherOptions {
1836
1811
  ignoreFilters: boolean;
@@ -1851,6 +1826,7 @@ interface GuildQueueTimeline {
1851
1826
  * @param options Options for timeline dispatcher
1852
1827
  */
1853
1828
  declare function useTimeline(): GuildQueueTimeline | null;
1829
+ declare function useTimeline(options: Partial<TimelineDispatcherOptions>): GuildQueueTimeline | null;
1854
1830
 
1855
1831
  /**
1856
1832
  * Global onAfterCreateStream handler
@@ -1871,6 +1847,7 @@ type VolumeDispatch = readonly [() => number, (volume: number | SetterFN) => boo
1871
1847
  * @param node Guild queue node resolvable
1872
1848
  */
1873
1849
  declare function useVolume(): VolumeDispatch;
1850
+ declare function useVolume(node: NodeResolvable): VolumeDispatch;
1874
1851
 
1875
1852
  interface ExtractorSession {
1876
1853
  id: string;
@@ -3296,4 +3273,4 @@ declare const DependencyReportGenerator: {
3296
3273
 
3297
3274
  declare const version: string;
3298
3275
 
3299
- export { AFilterGraph, AsyncQueue, AsyncQueueAcquisitionOptions, AsyncQueueEntry, AsyncQueueExceptionHandler, AudioFilters, BaseExtractor, Context, ContextReceiver, CreateStreamOps, DependenciesReport, DependencyReportGenerator, DiscordPlayerQueryResultCache, Encodable, EqualizerConfigurationPreset, ExtractorExecutionContext, ExtractorExecutionEvents, ExtractorExecutionFN, ExtractorExecutionResult, ExtractorInfo, 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, GuildQueueTimeline, 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 };
3276
+ export { AFilterGraph, AsyncQueue, type AsyncQueueAcquisitionOptions, AsyncQueueEntry, type AsyncQueueExceptionHandler, AudioFilters, BaseExtractor, Context, type ContextReceiver, type CreateStreamOps, type DependenciesReport, DependencyReportGenerator, DiscordPlayerQueryResultCache, type Encodable, EqualizerConfigurationPreset, ExtractorExecutionContext, type ExtractorExecutionEvents, type ExtractorExecutionFN, type ExtractorExecutionResult, type ExtractorInfo, type ExtractorResolvable, type ExtractorSearchContext, type ExtractorSession, type ExtractorStreamable, FFMPEG_ARGS_PIPED, FFMPEG_ARGS_STRING, FFMPEG_SRATE_REGEX, FFmpegFilterer, type FFmpegReport, type FFmpegStreamOptions, type FilterGraph, type FiltersName, type GuildNodeCreateOptions, type GuildNodeInit, GuildNodeManager, GuildQueue, type GuildQueueAFiltersCache, GuildQueueAudioFilters, GuildQueueEvent, type GuildQueueEvents, GuildQueueHistory, GuildQueuePlayerNode, GuildQueueStatistics, type GuildQueueStatisticsMetadata, type GuildQueueTimeline, type LrcGetParams, type LrcGetResult, LrcLib, type LrcSearchParams, type LrcSearchResult, type MaybeNull, type MetadataDispatch, type NextFunction, type NodeResolvable, type OnAfterCreateStreamHandler, type OnBeforeCreateStreamHandler, type PackageJSON, type PlayOptions, Player, PlayerEvent, type PlayerEvents, PlayerEventsEmitter, type PlayerInitOptions, type PlayerNodeInitializationResult, type PlayerNodeInitializerOptions, type PlayerProgressbarOptions, type PlayerSearchResult, type PlayerTimestamp, type PlayerTriggeredReason, Playlist, type PlaylistInitData, type PlaylistJSON, type PostProcessedResult, QueryCache, type QueryCacheOptions, type QueryCacheProvider, type QueryCacheResolverContext, type QueryExtractorSearch, QueryResolver, QueryType, type QueueFilters, QueueRepeatMode, type RawTrackData, type RequestEntity, type ResolvedQuery, type ResourcePlayOptions, type Runtime, type RuntimeType, type SearchOptions, type SearchQueryType, SearchResult, type SearchResultData, SequentialBucket, type SerializedPlaylist, type SerializedTrack, SerializedType, type SetterFN$1 as SetterFN, type SkipOptions, type StreamConfig, StreamDispatcher, type TimeData, type TimelineDispatcherOptions, Track, type TrackJSON, type TrackLike, type TrackResolvable, TrackSkipReason, type TrackSource, TypeUtil, Util, VALIDATE_QUEUE_CAP, type VoiceConnectConfig, type VoiceEvents, type VoiceStateHandler, VoiceUtils, type WithMetadata, createContext, createErisCompat, createFFmpegStream, decode, deserialize, encode, isErisProxy, onAfterCreateStream, onBeforeCreateStream, serialize, tryIntoThumbnailString, useContext, useHistory, useMainPlayer, useMetadata, usePlayer, useQueue, useTimeline, useVolume, version };