mirror of
https://github.com/Myxelium/Lunaris2.0.git
synced 2026-04-09 06:09:39 +00:00
22 lines
782 B
C#
22 lines
782 B
C#
using Discord.WebSocket;
|
|
using Lavalink4NET;
|
|
using MediatR;
|
|
|
|
namespace Lunaris2.Handler.MusicPlayer.DisconnectCommand;
|
|
|
|
public record DisconnectCommand(SocketSlashCommand Message) : IRequest;
|
|
|
|
public class DisconnectHandler(DiscordSocketClient client, IAudioService audioService) : IRequestHandler<DisconnectCommand>
|
|
{
|
|
public async Task Handle(DisconnectCommand command, CancellationToken cancellationToken)
|
|
{
|
|
var context = command.Message;
|
|
var player = await audioService.GetPlayerAsync(client, context, connectToVoiceChannel: true);
|
|
|
|
if (player is null)
|
|
return;
|
|
|
|
await player.DisconnectAsync(cancellationToken).ConfigureAwait(false);
|
|
await context.SendMessageAsync("Disconnected.", client).ConfigureAwait(false);
|
|
}
|
|
} |