discord-player-play-dl/src/Structures/Queue.ts

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-05-10 09:58:37 +05:00
import { Guild, Message, VoiceConnection } from 'discord.js';
2021-04-06 20:38:17 +05:00
import { Player } from '../Player';
2021-05-10 09:58:37 +05:00
import { PlayerOptions } from '../types/types';
import Track from './Track';
import { PlayerError } from '../utils/PlayerError';
2021-04-06 17:55:29 +05:00
2021-05-01 13:28:24 +05:00
export class Queue {
2021-05-10 09:58:37 +05:00
player: Player;
guild: Guild;
firstMessage: Message;
options: PlayerOptions = {};
tracks: Track[] = [];
voiceConnection: VoiceConnection = null;
2021-04-04 22:36:40 +05:00
2021-05-10 09:58:37 +05:00
constructor(player: Player, guild: Guild) {
2021-04-06 17:58:46 +05:00
Object.defineProperty(this, 'player', { value: player, enumerable: false });
2021-05-10 09:58:37 +05:00
this.guild = guild;
}
get playing() {
return this.tracks[0];
}
async play(message: Message, query: string | Track, firstResult?: boolean) {
return await this.player.play(message, query, firstResult);
}
addTrack(track: Track) {
if (!track || !(track instanceof Track)) throw new PlayerError('No track specified to add to the queue');
this.tracks.push(track);
return this;
}
addTracks(tracks: Track[]) {
this.tracks.push(...tracks);
return this;
2021-04-17 19:28:12 +05:00
}
2021-04-04 22:44:45 +05:00
}
2021-04-06 20:38:17 +05:00
export default Queue;