parent
c46a7282bb
commit
f9c6bf29fe
2 changed files with 8 additions and 4 deletions
|
@ -137,9 +137,10 @@ class Player extends EventEmitter {
|
|||
* @ignore
|
||||
* @param {Discord.Message} message
|
||||
* @param {string} query
|
||||
* @param {boolean} firstResult
|
||||
* @returns {Promise<Track>}
|
||||
*/
|
||||
_searchTracks (message, query) {
|
||||
_searchTracks (message, query, firstResult) {
|
||||
return new Promise(async (resolve) => {
|
||||
let tracks = []
|
||||
let updatedQuery = null
|
||||
|
@ -173,6 +174,8 @@ class Player extends EventEmitter {
|
|||
|
||||
if (tracks.length === 0) return this.emit('noResults', message, query)
|
||||
|
||||
if (firstResult) resolve(tracks[0])
|
||||
|
||||
this.emit('searchResults', message, query, tracks)
|
||||
|
||||
const collector = message.channel.createMessageCollector((m) => m.author.id === message.author.id, {
|
||||
|
@ -312,12 +315,13 @@ class Player extends EventEmitter {
|
|||
* Play a track in the server. Supported query types are `keywords`, `YouTube video links`, `YouTube playlists links`, `Spotify track link` or `SoundCloud song link`.
|
||||
* @param {Discord.Message} message Discord `message`
|
||||
* @param {String|Track} query Search query or a valid `Track` object.
|
||||
* @param {boolean} firstResult Whether the bot should play the first song found on youtube with the given query
|
||||
* @returns {Promise<void>}
|
||||
*
|
||||
* @example
|
||||
* client.player.play(message, "Despacito");
|
||||
*/
|
||||
async play (message, query) {
|
||||
async play (message, query, firstResult) {
|
||||
const isPlaying = this.isPlaying(message)
|
||||
if (this.util.isYTPlaylistLink(query)) {
|
||||
return this._handlePlaylist(message, query)
|
||||
|
@ -340,7 +344,7 @@ class Player extends EventEmitter {
|
|||
}
|
||||
}, message.author, this)
|
||||
} else {
|
||||
trackToPlay = await this._searchTracks(message, query)
|
||||
trackToPlay = await this._searchTracks(message, query, firstResult)
|
||||
}
|
||||
if (trackToPlay) {
|
||||
if (this.isPlaying(message)) {
|
||||
|
|
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
|
@ -25,7 +25,7 @@ declare module 'discord-player' {
|
|||
|
||||
public isPlaying(message: Message): boolean;
|
||||
public setFilters(message: Message, newFilters: Partial<Filters>): Promise<void>;
|
||||
public play(message: Message, query: string | Track): Promise<void>;
|
||||
public play(message: Message, query: string | Track, firstResult: boolean): Promise<void>;
|
||||
public pause(message: Message): void;
|
||||
public resume(message: Message): void;
|
||||
public stop(message: Message): void;
|
||||
|
|
Loading…
Reference in a new issue