You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to get this to work, so far I have got it to work with normal search terms but not a direct URL
My aim is to get this play command working via a youtube URL like ">play https://www.youtube.com/watch?v=pWO718iy5mY"
This is my current code for this command and I can't seem to work out what else to change:
[Command("play")]
public async Task PlayMusicURL(CommandContext ctx, Uri URL)
{
var userChannel = ctx.Member.VoiceState.Channel;
//PRE-EXECUTION CHECKS
if (ctx.Member.VoiceState == null || ctx.Member.VoiceState.Channel == null) //Checking to see if user is in a VC
{
await ctx.RespondAsync("Please enter a Voice channel");
return;
}
var lavaInstance = ctx.Client.GetLavalink(); //Getting instance of LavaLink
if (!lavaInstance.ConnectedNodes.Any()) //Check if the bot is connected to LavaLink
{
await ctx.RespondAsync("Connection is not Established");
return;
}
var node = lavaInstance.ConnectedNodes.Values.First();
if (userChannel.Type != ChannelType.Voice) //Check if the Bot is in a valid Voice Channel
{
await ctx.RespondAsync("Invalid Voice Channel");
return;
}
await node.ConnectAsync(userChannel); //Connect to the channel
var conn = node.GetGuildConnection(ctx.Member.VoiceState.Guild);
if (conn == null) //If the Bot failed to connect
{
await ctx.RespondAsync("Lavalink failed to connect");
return;
}
var loadResult = await node.Rest.GetTracksAsync(URL); //Search for the track using GetTracksAsync
if (loadResult.LoadResultType == LavalinkLoadResultType.LoadFailed || loadResult.LoadResultType == LavalinkLoadResultType.NoMatches)
{
await ctx.RespondAsync("Failed to find a track with this URL"); //Check to see if the Server failed or if there was no matches
return;
}
var track = loadResult.Tracks.First(); //Get the first entry in the search as it is the most accurate
await conn.PlayAsync(track); //Play the track
var MusicMSG = new DiscordMessageBuilder()
.AddEmbed(new DiscordEmbedBuilder()
.WithColor(DiscordColor.Azure)
.WithAuthor("𝕤𝕒𝕞.𝕛𝕖𝕤𝕦𝕤𝟠's Music System")
.WithTitle("Joined Channel " + userChannel.Name)
.WithDescription("Now Playing: " + track.Title + "\n" +
"Author: " + track.Author + "\n" +
"URL: " + track.Uri)
.WithFooter("Please use >pause & >resume and not >play when Pausing and Replaying the track")
);
await ctx.RespondAsync(MusicMSG);
}
I used the parameter Uri for URLs
Apparently the node.Rest.GetTracksAsync() has an overload for URLs but I don't understand how it works
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am trying to get this to work, so far I have got it to work with normal search terms but not a direct URL
My aim is to get this play command working via a youtube URL like ">play https://www.youtube.com/watch?v=pWO718iy5mY"
This is my current code for this command and I can't seem to work out what else to change:
Beta Was this translation helpful? Give feedback.
All reactions