Added support for youtube playlists, replaced multiple fetch requests with lavacord rest helpers

This commit is contained in:
Essem 2021-09-14 19:14:44 -05:00
parent c59a0bf0c4
commit 4caad42240
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
3 changed files with 9 additions and 8 deletions

View file

@ -1,4 +1,4 @@
import fetch from "node-fetch";
import { Rest } from "lavacord";
import format from "format-duration";
import MusicCommand from "../../classes/musicCommand.js";
@ -11,7 +11,7 @@ class NowPlayingCommand extends MusicCommand {
if (!this.message.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!";
const player = this.connection.player;
if (!player) return "I'm not playing anything!";
const track = await fetch(`http://${player.node.host}:${player.node.port}/decodetrack?track=${encodeURIComponent(player.track)}`, { headers: { Authorization: player.node.password } }).then(res => res.json());
const track = await Rest.decode(player.node, player.track);
const parts = Math.floor((player.state.position / track.length) * 10);
return {
"embed": {

View file

@ -10,7 +10,7 @@ class PlayCommand extends MusicCommand {
if (!this.args[0]) return "You need to provide what you want to play!";
const query = this.args.join(" ").trim();
const search = urlRegex.test(query) ? query : (searchRegex.test(query) ? query : `ytsearch:${query}`);
return await play(this.client, encodeURIComponent(search), this.message, true);
return await play(this.client, search, this.message, true);
}
static description = "Plays a song or adds it to the queue";