2023-03-24 00:09:26 +05:00
|
|
|
const { SlashCommandBuilder, PermissionsBitField } = require("discord.js"),
|
|
|
|
{ QueryType } = require("discord-player");
|
2022-08-02 17:18:47 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand"),
|
|
|
|
fs = require("fs");
|
|
|
|
|
|
|
|
class Clips extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("clips")
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDescription(client.translate("music/clips:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("music/clips:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("music/clips:DESCRIPTION", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2022-11-02 21:39:41 +05:00
|
|
|
.setDMPermission(false)
|
2023-07-05 00:58:06 +05:00
|
|
|
.addStringOption(option =>
|
|
|
|
option
|
|
|
|
.setName("query")
|
|
|
|
.setDescription(client.translate("music/clips:QUERY"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("music/clips:QUERY", null, "uk-UA"),
|
|
|
|
ru: client.translate("music/clips:QUERY", null, "ru-RU"),
|
|
|
|
})
|
|
|
|
.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) {
|
2023-03-24 00:09:26 +05:00
|
|
|
await interaction.deferReply();
|
|
|
|
|
|
|
|
const query = interaction.options.getString("query"),
|
|
|
|
voice = interaction.member.voice.channel;
|
|
|
|
if (!voice) return interaction.error("music/play:NO_VOICE_CHANNEL", null, { edit: true });
|
|
|
|
|
|
|
|
const perms = voice.permissionsFor(client.user);
|
|
|
|
if (!perms.has(PermissionsBitField.Flags.Connect) || !perms.has(PermissionsBitField.Flags.Speak)) return interaction.error("music/play:VOICE_CHANNEL_CONNECT", null, { edit: true });
|
|
|
|
|
|
|
|
client.player.play(interaction.member.voice.channel, query, {
|
|
|
|
nodeOptions: {
|
|
|
|
metadata: {
|
|
|
|
client,
|
2023-05-01 01:32:02 +05:00
|
|
|
channel: interaction.channel,
|
2023-03-24 00:09:26 +05:00
|
|
|
requestedBy: interaction.user,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
searchEngine: QueryType.FILE,
|
|
|
|
selfDeaf: true,
|
|
|
|
leaveOnEnd: false,
|
|
|
|
leaveOnStop: true,
|
|
|
|
skipOnNoStream: true,
|
|
|
|
bufferingTimeout: 1000,
|
|
|
|
});
|
2022-08-02 17:18:47 +05:00
|
|
|
|
2023-03-24 00:09:26 +05:00
|
|
|
interaction.editReply({
|
|
|
|
content: interaction.translate("music/play:ADDED_QUEUE", {
|
|
|
|
songName: query.substring(8, query.length - 4),
|
|
|
|
}),
|
2022-08-02 17:18:47 +05:00
|
|
|
});
|
|
|
|
}
|
2022-11-02 21:39:41 +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-03-26 18:31:19 +05:00
|
|
|
const query = interaction.options.getString("query"),
|
|
|
|
files = fs.readdirSync("./clips"),
|
|
|
|
results = files.filter(f => f.includes(query));
|
2023-03-24 00:09:26 +05:00
|
|
|
|
|
|
|
return interaction.respond(
|
2023-03-26 18:31:19 +05:00
|
|
|
results.slice(0, 25).map(file => ({
|
2023-03-24 00:09:26 +05:00
|
|
|
name: file.substring(0, file.length - 4),
|
|
|
|
value: `./clips/${file}`,
|
2023-07-05 00:58:06 +05:00
|
|
|
})),
|
|
|
|
);
|
2022-11-02 21:39:41 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Clips;
|