JaBa/commands/Music/clip.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

const Command = require("../../base/Command.js"),
fs = require("fs");
class Clip extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
super(client, {
name: "clip",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: [],
memberPermissions: [],
2021-12-26 19:29:37 +05:00
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
nsfw: false,
ownerOnly: false,
cooldown: 3000
});
}
2021-12-26 19:29:37 +05:00
async run(message, args) {
const voice = message.member.voice.channel;
2021-12-13 17:25:08 +05:00
const queue = this.client.player.getQueue(message);
2021-12-26 00:04:26 +05:00
const clip = args[0];
if (!voice) return message.error("music/play:NO_VOICE_CHANNEL");
2021-12-13 17:25:08 +05:00
if (queue) return message.error("music/clip:ACTIVE_QUEUE");
2021-12-26 00:04:26 +05:00
if (!clip) return message.error("music/clip:NO_ARG");
if (!fs.existsSync(`./clips/${clip}.mp3`)) return message.error("music/clip:NO_FILE", { file: clip });
try {
const connection = await voice.join();
await connection.voice.setSelfDeaf(true);
2021-12-26 00:04:26 +05:00
connection.play(`./clips/${clip}.mp3`)
.on("finish", () => {
voice.leave();
})
.on("error", err => {
voice.leave();
console.error(err);
});
} catch (error) {
console.error(error);
};
}
};
module.exports = Clip;