2023-03-24 00:09:26 +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 {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("play")
|
|
|
|
.setDescription(client.translate("music/play:DESCRIPTION"))
|
2023-03-26 18:31:19 +05:00
|
|
|
.setDescriptionLocalizations({ "uk": client.translate("music/play:DESCRIPTION", null, "uk-UA") })
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDMPermission(false)
|
2022-08-03 20:57:54 +05:00
|
|
|
.addStringOption(option => option.setName("query")
|
|
|
|
.setDescription(client.translate("music/play:QUERY"))
|
2023-03-26 18:31:19 +05:00
|
|
|
.setDescriptionLocalizations({ "uk": client.translate("music/play:QUERY", null, "uk-UA") })
|
2023-03-24 00:09:26 +05:00
|
|
|
.setRequired(true)
|
|
|
|
.setAutocomplete(true)),
|
2022-08-02 17:18:47 +05:00
|
|
|
aliases: [],
|
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-08-02 17:18:47 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
async onLoad() {
|
|
|
|
//...
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
2022-08-09 23:48:33 +05:00
|
|
|
* @param {Object} data
|
2022-08-02 17:18:47 +05:00
|
|
|
*/
|
|
|
|
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"),
|
|
|
|
voice = interaction.member.voice.channel;
|
2022-09-13 22:19:51 +05:00
|
|
|
if (!voice) return interaction.error("music/play:NO_VOICE_CHANNEL", null, { edit: true });
|
2023-01-09 01:39:13 +05:00
|
|
|
|
2022-08-02 17:18:47 +05:00
|
|
|
const perms = voice.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
|
|
|
|
2023-03-24 00:09:26 +05:00
|
|
|
const searchResult = await client.player.search(query, {
|
|
|
|
requestedBy: interaction.user,
|
2022-08-03 20:57:54 +05:00
|
|
|
});
|
|
|
|
|
2023-03-24 00:09:26 +05:00
|
|
|
if (!searchResult.hasTracks()) return interaction.error("music/play:NO_RESULT", { query }, { edit: true });
|
|
|
|
else {
|
|
|
|
client.player.play(interaction.member.voice.channel, searchResult, {
|
|
|
|
nodeOptions: {
|
|
|
|
metadata: {
|
|
|
|
channel: interaction.channel,
|
|
|
|
client,
|
|
|
|
requestedBy: interaction.user,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
selfDeaf: true,
|
|
|
|
leaveOnEnd: false,
|
|
|
|
leaveOnStop: true,
|
|
|
|
skipOnNoStream: true,
|
|
|
|
bufferingTimeout: 1000,
|
2022-08-28 16:45:05 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-03-24 00:09:26 +05:00
|
|
|
interaction.editReply({
|
|
|
|
content: interaction.translate("music/play:ADDED_QUEUE", {
|
|
|
|
songName: searchResult.hasPlaylist() ? searchResult.playlist.title : searchResult.tracks[0].title,
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
2022-08-02 17:18:47 +05:00
|
|
|
|
2023-03-24 00:09:26 +05:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
* @param {import("discord.js").AutocompleteInteraction} interaction
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
async autocompleteRun(client, interaction) {
|
2023-04-25 13:53:14 +05:00
|
|
|
const query = interaction.options.getString("query");
|
|
|
|
if (query.includes("http") || query === "") return;
|
|
|
|
|
|
|
|
const results = await client.player.search(query);
|
2023-03-24 00:09:26 +05:00
|
|
|
|
|
|
|
return interaction.respond(
|
|
|
|
results.tracks.slice(0, 10).map(track => ({
|
2023-04-06 00:29:13 +05:00
|
|
|
name: (`${track.author} - ${track.title}`.length >= 100 & `${track.author} - ${track.title}`.slice(0, 90) + "...") || `${track.author} - ${track.title}`,
|
2023-03-24 00:09:26 +05:00
|
|
|
value: track.url,
|
|
|
|
}),
|
|
|
|
));
|
2022-08-02 17:18:47 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Play;
|