Skip to content

Commit

Permalink
[ci skip] fix: fix implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulalaby committed Jan 22, 2025
1 parent c1e41ad commit d835be5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed class ControlCommands : ApplicationCommandsModule
[SlashCommand("connect", "Connects to a channel")]
public async Task ConnectAsync(InteractionContext ctx, [Option("channel", "Channel to connect to"), ChannelTypes(ChannelType.Voice, ChannelType.Stage)] DiscordChannel voiceChannel)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral().WithContent($"Trying to switch to {voiceChannel.Mention}"));
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral().WithContent($"Trying to connect to {voiceChannel.Mention}"));
try
{
ArgumentNullException.ThrowIfNull(ctx.Guild);
Expand Down Expand Up @@ -228,10 +228,31 @@ public async Task SeekAsync(InteractionContext ctx, [Option("position", "The tot
[SlashCommandGroup("queue", "Music queue commands")]
public sealed class QueueCommands : ApplicationCommandsModule
{
[SlashCommand("play", "Starts the queue playback")]
public async Task PlayQueueAsync(InteractionContext ctx)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral().WithContent("Trying to play.."));
try
{
ArgumentNullException.ThrowIfNull(ctx.Guild);
var player = ctx.Client.GetLavalink().GetGuildPlayer(ctx.Guild);
ArgumentNullException.ThrowIfNull(player);
player.PlayQueue();
}
catch (ArgumentNullException)
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Make sure you're connected to a channel."));
}
catch (Exception ex)
{
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(ex.Message ?? "No message"));
}
}

[SlashCommand("add_playlist", "Adds a playlist to the queue (youtube.com/playlist?list=XYZ)")]
public async Task QueuePlaylistAsync(InteractionContext ctx, [Option("url", "The url to play")] string url)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral().WithContent("Please wait.."));
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral().WithContent("Adding playlist.."));
try
{
ArgumentNullException.ThrowIfNull(ctx.Guild);
Expand All @@ -257,8 +278,6 @@ public async Task QueuePlaylistAsync(InteractionContext ctx, [Option("url", "The

player.AddToQueue(playlist);
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"Added {playlist.Tracks.Count.ToString().Bold()} songs from {playlist.Info.Name.Bold()} to the queue."));
if (player.Player.Paused)
player.PlayQueue();
}
catch (ArgumentNullException)
{
Expand All @@ -273,7 +292,7 @@ public async Task QueuePlaylistAsync(InteractionContext ctx, [Option("url", "The
[SlashCommand("add_song", "Adds a song to the queue")]
public async Task QueueSongAsync(InteractionContext ctx, [Option("url", "The url to play")] string url)
{
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral().WithContent("Please wait.."));
await ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, new DiscordInteractionResponseBuilder().AsEphemeral().WithContent("Adding song.."));
try
{
ArgumentNullException.ThrowIfNull(ctx.Guild);
Expand Down Expand Up @@ -303,8 +322,6 @@ public async Task QueueSongAsync(InteractionContext ctx, [Option("url", "The url

player.AddToQueue(track);
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"Added {track.Info.Title.Bold()} by {track.Info.Author.Italic()} to the queue."));
if (player.Player.Paused)
player.PlayQueue();
}
catch (ArgumentNullException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static SimpleMusicCommandsExtension UseSimpleMusicCommands(this DiscordCl
cfg ??= new();

var smc = new SimpleMusicCommandsExtension(cfg);
client.UseLavalink();
client.AddExtension(smc);
return smc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void RegisterMusicCommands(List<ulong>? guildIds = null)
/// </summary>
public async Task ConnectAsync()
{
var ex = this.Client.UseLavalink();
var ex = this.Client.GetLavalink();
await ex.ConnectAsync(this.Configuration);
}
}

0 comments on commit d835be5

Please sign in to comment.