-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
27 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,28 @@ | ||
use crate::Context; | ||
use poise::serenity_prelude::client::Context as SerenityContext; | ||
use poise::serenity_prelude::model::id::GuildId; | ||
use songbird::input::ffmpeg; | ||
use songbird::SerenityInit; | ||
use youtube_dl::YoutubeDl; | ||
|
||
/// Description of the new function | ||
/// | ||
/// This command allows you to play a YouTube video in VC. | ||
/// ``` | ||
/// ~ytplay | ||
/// ``` | ||
#[poise::command(prefix_command, slash_command)] | ||
pub async fn ytplay(ctx: Context<'_>) -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | ||
pub async fn ytplay( | ||
ctx: Context<'_>, | ||
url: String, | ||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | ||
ctx.defer().await?; | ||
|
||
// ... | ||
// Fetch audio stream from YouTube video | ||
let video = YoutubeDl::new(&url).run().await?; | ||
let audio = video.get_best_audio().ok_or("No audio found")?; | ||
|
||
// Connect to voice channel and play audio | ||
let manager = songbird::get(&ctx.discord).await.expect("Songbird Voice client placed in at initialisation."); | ||
let handler_lock = manager.get(ctx.guild_id).ok_or("Not in a voice channel")?; | ||
let mut handler = handler_lock.lock().await; | ||
|
||
let source = ffmpeg(audio.url).await?; | ||
handler.play_source(source); | ||
|
||
Ok(()) | ||
} |