Skip to content

Commit

Permalink
feat: play local mp3 files
Browse files Browse the repository at this point in the history
  • Loading branch information
eritislami committed Dec 2, 2020
1 parent e877e1a commit 1ce79e8
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
41 changes: 41 additions & 0 deletions commands/clip.js
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 0 deletions commands/clips.js
Original file line number Diff line number Diff line change
@@ -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);
});
}
};
Empty file added sounds/putmusichere.mp3
Empty file.

0 comments on commit 1ce79e8

Please sign in to comment.