feat: Music support #62

Merged
Anri merged 43 commits from feat/music into main 2023-02-12 01:11:10 +01:00
Showing only changes of commit 593da97e33 - Show all commits

View file

@ -5,7 +5,7 @@ import {
GuildResolvable, GuildResolvable,
VoiceBasedChannel, VoiceBasedChannel,
} from "discord.js"; } from "discord.js";
import { Metadata } from "../../modules/metadata"; import { Metadata } from "../../utils/metadata";
import { getLocale, getLocalizations } from "../../utils/locales"; import { getLocale, getLocalizations } from "../../utils/locales";
import { getFilename } from "../../utils/misc"; import { getFilename } from "../../utils/misc";
@ -84,20 +84,34 @@ export default {
} }
await interaction.deferReply(); await interaction.deferReply();
const track = await client.player const result = await client.player
.search(query, { .search(query, {
requestedBy: interaction.user, requestedBy: interaction.user,
}) })
.then((x) => x.tracks[0]); .then((x) => x);
if (!track) { if (!result.tracks[0]) {
return await interaction.followUp({ content: `❌ | \`${query}\` ${loc.get("c_play4")}.` }); return await interaction.followUp({ content: `❌ | \`${query}\` ${loc.get("c_play4")}.` });
} }
queue.play(track); let title;
if (result.playlist) {
queue.addTracks(result.playlist.tracks);
title = result.playlist.title;
} else {
// TODO: Ask user which result to choose
const track = result.tracks[0];
queue.addTrack(track);
title = track.title;
}
if (!queue.playing) {
queue.play();
}
return await interaction.followUp({ return await interaction.followUp({
content: `⏱️ | \`${track.title}\` ${loc.get("c_play5")}.`, content: `⏱️ | \`${title}\` ${loc.get("c_play5")}.`,
}); });
}, },
}; };