2024-04-29 15:57:02 +05:00
|
|
|
const { SlashCommandBuilder, PermissionsBitField } = require("discord.js");
|
2022-09-10 23:38:11 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
2022-08-02 17:18:47 +05:00
|
|
|
|
|
|
|
class Play extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../base/Client")} client
|
2022-08-02 17:18:47 +05:00
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("play")
|
|
|
|
.setDescription(client.translate("music/play:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("music/play:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("music/play:DESCRIPTION", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDMPermission(false)
|
2023-07-05 00:58:06 +05:00
|
|
|
.addStringOption(option =>
|
|
|
|
option
|
|
|
|
.setName("query")
|
|
|
|
.setDescription(client.translate("music/play:QUERY"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("music/play:QUERY", null, "uk-UA"),
|
|
|
|
ru: client.translate("music/play:QUERY", null, "ru-RU"),
|
|
|
|
})
|
2024-04-29 15:57:02 +05:00
|
|
|
.setRequired(true),
|
2023-07-05 00:58:06 +05:00
|
|
|
),
|
2022-08-02 17:18:47 +05:00
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-08-02 17:18:47 +05:00
|
|
|
});
|
|
|
|
}
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2022-08-02 17:18:47 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2022-08-02 17:18:47 +05:00
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
|
|
|
*/
|
|
|
|
async execute(client, interaction) {
|
|
|
|
await interaction.deferReply();
|
2022-08-29 21:31:36 +05:00
|
|
|
|
2023-01-09 01:39:13 +05:00
|
|
|
const query = interaction.options.getString("query"),
|
2024-04-29 15:57:02 +05:00
|
|
|
voice = interaction.member.voice;
|
2024-04-29 16:09:43 +05:00
|
|
|
if (!voice.channel) return interaction.error("music/play:NO_VOICE_CHANNEL", null, { edit: true });
|
2023-01-09 01:39:13 +05:00
|
|
|
|
2024-04-29 15:57:02 +05:00
|
|
|
const perms = voice.channel.permissionsFor(client.user);
|
2022-09-13 22:19:51 +05:00
|
|
|
if (!perms.has(PermissionsBitField.Flags.Connect) || !perms.has(PermissionsBitField.Flags.Speak)) return interaction.error("music/play:VOICE_CHANNEL_CONNECT", null, { edit: true });
|
2022-08-02 17:18:47 +05:00
|
|
|
|
2024-04-29 15:57:02 +05:00
|
|
|
const player = await client.lavalink.createPlayer({
|
|
|
|
guildId: interaction.guildId,
|
|
|
|
voiceChannelId: voice.channelId,
|
|
|
|
textChannelId: interaction.channelId,
|
|
|
|
selfDeaf: true,
|
|
|
|
selfMute: false,
|
|
|
|
volume: 100,
|
2022-08-03 20:57:54 +05:00
|
|
|
});
|
|
|
|
|
2024-04-29 15:57:02 +05:00
|
|
|
await player.connect();
|
|
|
|
|
|
|
|
const res = await player.search({ query }, interaction.member);
|
|
|
|
|
|
|
|
if (res.loadType === "playlist") await player.queue.add(res.tracks);
|
|
|
|
else if (res.loadType === "search") await player.queue.add(res.tracks[0]);
|
|
|
|
else if (res.loadType === "track") await player.queue.add(res.tracks[0]);
|
|
|
|
else console.log(res);
|
|
|
|
|
|
|
|
if (!player.playing) await player.play();
|
|
|
|
|
|
|
|
interaction.editReply({
|
|
|
|
content: interaction.translate("music/play:ADDED_QUEUE", {
|
|
|
|
songName: res.loadType === "playlist" ? res.playlist.name : `${res.tracks[0].info.title} - ${res.tracks[0].info.author}`,
|
|
|
|
}),
|
|
|
|
});
|
2023-03-24 00:09:26 +05:00
|
|
|
}
|
2022-08-02 17:18:47 +05:00
|
|
|
|
2023-03-24 00:09:26 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2023-03-24 00:09:26 +05:00
|
|
|
* @param {import("discord.js").AutocompleteInteraction} interaction
|
|
|
|
* @returns
|
|
|
|
*/
|
2024-04-29 15:57:02 +05:00
|
|
|
// async autocompleteRun(client, interaction) { // TODO: Works from time to time
|
|
|
|
// const query = interaction.options.getString("query");
|
|
|
|
// if (query === "") return;
|
|
|
|
|
|
|
|
// if (!client.lavalink.players.get(interaction.guildId)) {
|
|
|
|
// const player = await client.lavalink.createPlayer({
|
|
|
|
// guildId: interaction.guildId,
|
|
|
|
// voiceChannelId: interaction.member.voice.channelId,
|
|
|
|
// textChannelId: interaction.channelId,
|
|
|
|
// selfDeaf: true,
|
|
|
|
// selfMute: false,
|
|
|
|
// volume: 100,
|
|
|
|
// });
|
|
|
|
|
|
|
|
// const results = await player.search({ query }, interaction.member);
|
|
|
|
// if (results.loadType === "empty") return interaction.respond([{ name: "Nothing found", "value": "https://www.youtube.com/watch?v=dQw4w9WgXcQ" }]);
|
|
|
|
// const tracks = [];
|
|
|
|
|
|
|
|
// results.tracks
|
|
|
|
// .map(t => ({
|
|
|
|
// name: `YouTube: ${`${t.info.title} - ${t.info.author} (${client.functions.printDate(client, t.info.duration, null, interaction.data.guild.lanugage)})`.length > 75 ? `${`${t.info.title} - ${t.info.author}`.substring(0, 75)}... (${client.functions.printDate(client, t.info.duration, null, interaction.data.guild.lanugage)})` : `${t.info.title} - ${t.info.author} (${client.functions.printDate(client, t.info.duration, null, interaction.data.guild.lanugage)})`}`,
|
|
|
|
// value: t.info.uri,
|
|
|
|
// }))
|
|
|
|
// .forEach(t => tracks.push({ name: t.name, value: t.value }));
|
|
|
|
|
|
|
|
// return interaction.respond(tracks);
|
|
|
|
// }
|
|
|
|
// }
|
2022-08-02 17:18:47 +05:00
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Play;
|