Skip to content

Commit

Permalink
Fixed ytdl bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Struck713 committed Sep 17, 2023
1 parent 300a37c commit 082278b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 51 deletions.
47 changes: 4 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"discord.js": "^14.11.0",
"ffmpeg-static": "^5.1.0",
"libsodium-wrappers": "^0.7.11",
"yt-dlp-wrap": "^2.3.11",
"ytdl-core": "^4.11.5"
"yt-dlp-wrap": "^2.3.12"
},
"devDependencies": {
"@types/node": "^20.4.1",
Expand Down
21 changes: 15 additions & 6 deletions src/lib/voice.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { YOUTUBE } from "../../config.json";

import { AudioPlayer, AudioPlayerStatus, AudioResource, createAudioPlayer, createAudioResource, getVoiceConnection, joinVoiceChannel } from "@discordjs/voice";
import { VoiceBasedChannel } from "discord.js";
import ytdl from "ytdl-core";
import { YoutubeMetadata } from "./utils/youtube";
import { voiceManager } from "../app";
import { YoutubeMetadata } from "./utils/youtube";

//const ytdl = new YTDLPWrap('C:/Users/Noah/Programming/JavaScript/BarbarianBot_v2/binaries/yt-dlp.exe');
import YTDlpWrap from "yt-dlp-wrap";
const ytdl = new YTDlpWrap(YOUTUBE.BINARY);

export class VoiceManager {

Expand Down Expand Up @@ -89,9 +91,16 @@ export class VoiceConnection {
let voiceConnection = this.get();
if (!voiceConnection) return false;

const stream = ytdl(url, { filter: "audioonly" })
.on("error", _ => this.next());
this.resource = createAudioResource(stream);
const stream = await ytdl.exec(
[
"-o",
"-",
url,
"-f",
"bestaudio[ext=m4a],bestaudio[ext=webm]"
]
);
this.resource = createAudioResource(stream.ytDlpProcess?.stdout!);
this.audioPlayer.play(this.resource);

return true;
Expand Down

0 comments on commit 082278b

Please sign in to comment.