From c6ac32561cbda3c79629225dbfb9525f0369e1a5 Mon Sep 17 00:00:00 2001 From: JonnyBro Date: Sat, 8 Jan 2022 04:14:04 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20clip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/Economy/rob.js | 2 +- commands/Music/clip.js | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/commands/Economy/rob.js b/commands/Economy/rob.js index 0822be45..6a4b4017 100644 --- a/commands/Economy/rob.js +++ b/commands/Economy/rob.js @@ -46,7 +46,7 @@ class Rob extends Command { const itsAWon = Math.floor(this.client.functions.randomNum(0, 100) < 25); if (itsAWon) { - const toWait = Date.now() + 6 * (60 * 60000); + const toWait = Date.now() + 6 * (60 * 60000); // 6 hours memberData.cooldowns.rob = toWait; memberData.markModified("cooldowns"); await memberData.save(); diff --git a/commands/Music/clip.js b/commands/Music/clip.js index 10713edc..b951c873 100644 --- a/commands/Music/clip.js +++ b/commands/Music/clip.js @@ -1,5 +1,6 @@ const Command = require("../../base/Command.js"), - fs = require("fs"); + fs = require("fs"), + { joinVoiceChannel, createAudioResource, createAudioPlayer } = require("@discordjs/voice"); class Clip extends Command { constructor(client) { @@ -29,17 +30,21 @@ class Clip extends Command { 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); + const connection = joinVoiceChannel({ + channelId: voice.id, + guildId: message.guild.id, + adapterCreator: message.guild.voiceAdapterCreator + }); - connection.play(`./clips/${clip}.mp3`) - .on("finish", () => { - voice.leave(); - }) - .on("error", err => { - voice.leave(); - console.error(err); + const resource = createAudioResource(fs.createReadStream(`./clips/${clip}.mp3`)); + const player = createAudioPlayer() + .on("error", error => { + connection.destroy(); + console.error("Error:", error.message, "with track", error.resource.metadata.title); }); + + player.play(resource); + connection.subscribe(player); } catch (error) { console.error(error); };