diff --git a/commands/clip.js b/commands/clip.js new file mode 100644 index 000000000..14e06ae86 --- /dev/null +++ b/commands/clip.js @@ -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 ").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); + } + } +}; diff --git a/commands/clips.js b/commands/clips.js new file mode 100644 index 000000000..8c1e1995b --- /dev/null +++ b/commands/clips.js @@ -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); + }); + } +}; diff --git a/sounds/putmusichere.mp3 b/sounds/putmusichere.mp3 new file mode 100644 index 000000000..e69de29bb