mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-22 05:04:58 +05:00
90 lines
No EOL
2.3 KiB
JavaScript
90 lines
No EOL
2.3 KiB
JavaScript
const { SlashCommandBuilder, PermissionsBitField } = require("discord.js"),
|
|
{ QueryType } = require("discord-player");
|
|
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")
|
|
.setDescription(client.translate("music/clips:DESCRIPTION"))
|
|
.setDMPermission(false)
|
|
.addStringOption(option => option.setName("query")
|
|
.setDescription(client.translate("music/clips:QUERY"))
|
|
.setRequired(true)
|
|
.setAutocomplete(true)),
|
|
aliases: [],
|
|
dirname: __dirname,
|
|
ownerOnly: false,
|
|
});
|
|
}
|
|
/**
|
|
*
|
|
* @param {import("../../base/JaBa")} client
|
|
*/
|
|
async onLoad() {
|
|
//...
|
|
}
|
|
/**
|
|
*
|
|
* @param {import("../../base/JaBa")} client
|
|
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
|
* @param {Object} data
|
|
*/
|
|
async execute(client, interaction) {
|
|
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: {
|
|
channel: interaction.channel,
|
|
client,
|
|
requestedBy: interaction.user,
|
|
},
|
|
},
|
|
searchEngine: QueryType.FILE,
|
|
selfDeaf: true,
|
|
leaveOnEnd: false,
|
|
leaveOnStop: true,
|
|
skipOnNoStream: true,
|
|
bufferingTimeout: 1000,
|
|
});
|
|
|
|
interaction.editReply({
|
|
content: interaction.translate("music/play:ADDED_QUEUE", {
|
|
songName: query.substring(8, query.length - 4),
|
|
}),
|
|
});
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {import("../../base/JaBa")} client
|
|
* @param {import("discord.js").AutocompleteInteraction} interaction
|
|
* @returns
|
|
*/
|
|
async autocompleteRun(client, interaction) {
|
|
const files = fs.readdirSync("./clips");
|
|
|
|
return interaction.respond(
|
|
files.slice(0, 10).map(file => ({
|
|
name: file.substring(0, file.length - 4),
|
|
value: `./clips/${file}`,
|
|
}),
|
|
));
|
|
}
|
|
}
|
|
|
|
module.exports = Clips; |