feat: play local mp3 files

This commit is contained in:
Erit Islami 2020-12-02 10:17:31 +01:00
parent e877e1a6e9
commit 1ce79e8fc6
No known key found for this signature in database
GPG Key ID: 43B7DA4FF32E5774
3 changed files with 60 additions and 0 deletions

41
commands/clip.js Normal file
View File

@ -0,0 +1,41 @@
module.exports = {
name: "clip",
description: "Plays a clip sound",
async execute(message, args) {
const { channel } = message.member.voice;
const queue = message.client.queue.get(message.guild.id);
if (!args.length) return message.reply("Usage: /clip <name>").catch(console.error);
if (queue) return message.reply("Can't play clip because there is an active queue.");
if (!channel) return message.reply("You need to join a voice channel first!").catch(console.error);
const queueConstruct = {
textChannel: message.channel,
channel,
connection: null,
songs: [],
loop: false,
volume: 100,
playing: true
};
message.client.queue.set(message.guild.id, queueConstruct);
try {
queueConstruct.connection = await channel.join();
const dispatcher = queueConstruct.connection
.play(`./sounds/${args[0]}.mp3`)
.on("finish", () => {
message.client.queue.delete(message.guild.id);
channel.leave();
})
.on("error", err => {
message.client.queue.delete(message.guild.id);
channel.leave();
console.error(err);
});
} catch (error) {
console.error(error);
}
}
};

19
commands/clips.js Normal file
View File

@ -0,0 +1,19 @@
const fs = require("fs");
module.exports = {
name: "clips",
description: "List all clips",
execute(message) {
fs.readdir("./sounds", function(err, files) {
if (err) return console.log("Unable to read directory: " + err);
let clips = [];
files.forEach(function(file) {
clips.push(file.substring(0, file.length - 4));
});
message.reply(`${clips.join(" ")}`).catch(console.error);
});
}
};

0
sounds/putmusichere.mp3 Normal file
View File