2022-08-04 22:06:26 +05:00
|
|
|
const { SlashCommandBuilder, PermissionsBitField } = require("discord.js");
|
2022-08-08 12:50:08 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand"),
|
|
|
|
playdl = require("play-dl");
|
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"))
|
2022-08-03 20:57:54 +05:00
|
|
|
.addStringOption(option => option.setName("query")
|
|
|
|
.setDescription(client.translate("music/play:QUERY"))
|
2022-08-02 17:18:47 +05:00
|
|
|
.setRequired(true)),
|
|
|
|
aliases: [],
|
|
|
|
dirname: __dirname,
|
|
|
|
guildOnly: true,
|
|
|
|
ownerOnly: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
async onLoad() {
|
|
|
|
//...
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../../base/JaBa")} client
|
|
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
|
|
|
* @param {Array} data
|
|
|
|
*/
|
|
|
|
async execute(client, interaction) {
|
|
|
|
await interaction.deferReply();
|
|
|
|
const voice = interaction.member.voice.channel;
|
2022-08-06 22:35:01 +05:00
|
|
|
if (!voice) return interaction.editReply({ content: interaction.translate("music/play:NO_VOICE_CHANNEL") });
|
2022-08-03 20:57:54 +05:00
|
|
|
const query = interaction.options.getString("query");
|
2022-08-02 17:18:47 +05:00
|
|
|
const perms = voice.permissionsFor(client.user);
|
2022-08-06 22:35:01 +05:00
|
|
|
if (!perms.has(PermissionsBitField.Flags.Connect) || !perms.has(PermissionsBitField.Flags.Speak)) return interaction.editReply({ content: interaction.translate("music/play:VOICE_CHANNEL_CONNECT") });
|
2022-08-02 17:18:47 +05:00
|
|
|
|
2022-08-03 20:57:54 +05:00
|
|
|
const searchResult = await client.player.search(query, {
|
|
|
|
requestedBy: interaction.user,
|
2022-08-08 12:50:08 +05:00
|
|
|
// searchEngine: "jaba"
|
2022-08-03 20:57:54 +05:00
|
|
|
}).catch(() => {});
|
|
|
|
if (!searchResult || !searchResult.tracks.length) return interaction.editReply({
|
|
|
|
content: interaction.translate("music/play:NO_RESULT", {
|
|
|
|
query
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
|
|
|
const queue = client.player.getQueue(interaction.guildId) || client.player.createQueue(interaction.guild, {
|
|
|
|
metadata: {
|
|
|
|
channel: interaction.channel
|
|
|
|
},
|
2022-08-04 22:06:26 +05:00
|
|
|
leaveOnEnd: true,
|
|
|
|
leaveOnStop: true,
|
|
|
|
bufferingTimeout: 1000,
|
|
|
|
disableVolume: false,
|
2022-08-08 12:50:08 +05:00
|
|
|
spotifyBridge: false,
|
|
|
|
async onBeforeCreateStream(track, source) {
|
|
|
|
if (source === "youtube" || source === "soundcloud")
|
|
|
|
return (await playdl.stream(track.url, { discordPlayerCompatibility: true })).stream;
|
|
|
|
}
|
2022-08-03 20:57:54 +05:00
|
|
|
});
|
|
|
|
|
2022-08-04 22:06:26 +05:00
|
|
|
searchResult.playlist ? queue.addTracks(searchResult.tracks) : queue.addTrack(searchResult.tracks[0]);
|
2022-08-03 20:57:54 +05:00
|
|
|
|
2022-08-02 17:18:47 +05:00
|
|
|
try {
|
2022-08-03 20:57:54 +05:00
|
|
|
if (!queue.connection) await queue.connect(interaction.member.voice.channel);
|
|
|
|
if (!queue.playing) await queue.play();
|
2022-08-02 17:18:47 +05:00
|
|
|
|
|
|
|
interaction.editReply({
|
2022-08-03 20:57:54 +05:00
|
|
|
content: interaction.translate("music/play:ADDED_QUEUE", {
|
|
|
|
songName: searchResult.playlist ? searchResult.playlist.title : searchResult.tracks[0].title
|
|
|
|
})
|
2022-08-02 17:18:47 +05:00
|
|
|
});
|
|
|
|
} catch (e) {
|
2022-08-03 20:57:54 +05:00
|
|
|
client.player.deleteQueue(interaction.guildId);
|
2022-08-02 17:18:47 +05:00
|
|
|
console.error(e);
|
2022-08-06 22:35:01 +05:00
|
|
|
return interaction.editReply({
|
|
|
|
content: interaction.translate("music/play:ERR_OCCURRED", {
|
|
|
|
error: e
|
|
|
|
})
|
|
|
|
});
|
2022-08-02 17:18:47 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Play;
|