public async Task Stop(CommandContext ctx) { LavalinkNodeConnection node = ctx.Client.GetLavalink().ConnectedNodes.Values.First(); LavalinkGuildConnection conn = node.GetGuildConnection(ctx.Member.VoiceState.Guild); if (ctx.Member.VoiceState.Channel != conn.Channel) { await ctx.RespondAsync("You are not in a VC with me."); return; } if (conn == null) { await ctx.RespondAsync("Lavalink not connected"); return; } if (conn.CurrentState.CurrentTrack == null) { await ctx.RespondAsync("Nothing playing"); return; } try { LavalinkService.Instance.Queues.Remove(ctx.Guild); } catch { } await conn.StopAsync(); await conn.DisconnectAsync(); await ctx.RespondAsync("Bye"); }
public async Task Leave(CommandContext ctx) { LavalinkNodeConnection lavalinkNodeConnection = await Connections.GetNodeConnection(ctx); LavalinkGuildConnection lavalinkGuildConnection = lavalinkNodeConnection.GetGuildConnection(ctx.Guild); if (lavalinkGuildConnection != null) { await lavalinkGuildConnection.DisconnectAsync(); queues[ctx.Guild.Id].Clear(); loops[ctx.Guild.Id] = false; Messaging messaging = new Messaging(ctx); await messaging.RespondContent()("Take it sleazy!"); } }
public async Task Sair(CommandContext context, [Description("Canal que você quer que o BOT se desconecte.")] DiscordChannel channel) { if (context.Channel.Id == BotClient.configJson.ComandosBotCanalId) { guildConnection = BotClient.LavalinkNode.GetGuildConnection(await BotClient.Lavalink.Client.GetGuildAsync(BotClient.configJson.ServerId).ConfigureAwait(false)); BotClient.IsSongPlaying = false; if (guildConnection == null) { await context.RespondAsync($"{context.User.Username} eu não estou conectado a nenhum canal de voz!").ConfigureAwait(false); return; } await guildConnection.DisconnectAsync(); await context.RespondAsync($"Ok {context.User.Username}! Eu me desconectei do canal: #{channel.Name}!").ConfigureAwait(false); } }
private async Task DiscordSocketClosed(LavalinkGuildConnection lvc, WebSocketCloseEventArgs e) { if (e.Code == 4014) { return; } if (e.Code == 1001 || e.Code == 1006 || e.Code == 4000) { var track = lvc.CurrentState?.CurrentTrack; var time = lvc.CurrentState?.PlaybackPosition; var ch = lvc.Channel; await lvc.DisconnectAsync(); var newLvc = await ShimakazeBot.lvn.ConnectAsync(ch); if (track != null) { await newLvc.PlayAsync(track); if (time != null) { await newLvc.SeekAsync(time.Value); } } return; } string str = $"Discord socket closed:" + $"\n - Code: {e.Code}" + $"\n - Reason: {e.Reason}" + $"\n - Remote: {e.Remote}" + $"\n - Channel: {lvc?.Channel.Name} ({lvc?.Guild.Name})"; ShimakazeBot.SendToDebugRoom(str); return; }