yt link download

This commit is contained in:
Stanislaw
2021-12-27 10:31:47 +01:00
parent 481a1f3f25
commit cee3c07409
4 changed files with 7 additions and 4 deletions

Binary file not shown.

View File

@@ -5,12 +5,13 @@ module.exports = {
const ytsr = require('ytsr'); const ytsr = require('ytsr');
const path = require('path'); const path = require('path');
const discord = require('discord.js'); const discord = require('discord.js');
const fs = require('fs')
const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require('@discordjs/voice'); const { joinVoiceChannel, createAudioPlayer, createAudioResource } = require('@discordjs/voice');
let connection; let connection;
let aplay; let aplay;
let queue; let queue;
function link(msg) { async function link(msg) {
let request = msg.content.slice(path.basename(__filename).length + cl.cfg.prefix.length - 3); let request = msg.content.slice(path.basename(__filename).length + cl.cfg.prefix.length - 3);
if (request.trim() == "") { if (request.trim() == "") {
msg.reply("Dej link albo tagi albo weź i spierdalaj"); msg.reply("Dej link albo tagi albo weź i spierdalaj");
@@ -18,13 +19,15 @@ module.exports = {
request = request.trim() request = request.trim()
if (ytdl.validateURL(request)) { if (ytdl.validateURL(request)) {
msg.reply("Poprawny link"); msg.reply("Poprawny link");
return request; link = './sound/' + msg.member.voice.channel.id + '.mp3'
await ytdl(request).pipe(fs.createWriteStream(link));
return link;
} else { } else {
msg.reply("Kurwo wenecka daj prawdziwy link a nie jaja sobie robisz"); msg.reply("Kurwo wenecka daj prawdziwy link a nie jaja sobie robisz");
} }
} else { } else {
msg.reply("Szukasz:" + request); msg.reply("Szukasz:" + request);
} }
} }
if (!connection) { if (!connection) {
@@ -36,7 +39,7 @@ module.exports = {
}) })
} }
aplay = createAudioPlayer(); aplay = createAudioPlayer();
let song = createAudioResource('C:/Users/Stachu/Documents/GitHub/bot/src/sound/afro.mp3') let song = createAudioResource(link(msg));
aplay.play(song); aplay.play(song);
connection.subscribe(aplay); connection.subscribe(aplay);
aplay.on('error', error => { aplay.on('error', error => {

Binary file not shown.

Binary file not shown.