Add Join and Play handlers, Expand Command Builder functionality

This commit is contained in:
Myx
2024-04-14 16:06:18 +02:00
parent f7b54ca80c
commit 95ab1281a4
16 changed files with 293 additions and 20 deletions

View File

@@ -0,0 +1,34 @@
using Discord;
using Discord.WebSocket;
using MediatR;
using Victoria.Node;
namespace Lunaris2.Handler.MusicPlayer.JoinCommand;
public record JoinCommand(SocketSlashCommand Message) : IRequest;
public class JoinHandler : IRequestHandler<JoinCommand>
{
private readonly LavaNode _lavaNode;
private readonly DiscordSocketClient _client;
public JoinHandler(LavaNode lavaNode, DiscordSocketClient client)
{
_lavaNode = lavaNode;
_client = client;
}
public async Task Handle(JoinCommand command, CancellationToken cancellationToken)
{
var context = command.Message;
await _lavaNode.EnsureConnected();
if (_lavaNode.HasPlayer(context.GetGuild(_client))) {
await context.RespondAsync("I'm already connected to a voice channel!");
return;
}
await context.JoinVoiceChannel(_lavaNode);
}
}