fix wrong channel
This commit is contained in:
parent
c9c7a15e3a
commit
59aa6a13a3
@ -3,6 +3,7 @@ using Discord.Audio;
|
|||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Kasbot.Extensions;
|
using Kasbot.Extensions;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Kasbot.Services
|
namespace Kasbot.Services
|
||||||
{
|
{
|
||||||
@ -23,9 +24,6 @@ namespace Kasbot.Services
|
|||||||
var conn = new Connection();
|
var conn = new Connection();
|
||||||
IAudioClient audioClient = await voiceChannel.ConnectAsync(selfDeaf: true);
|
IAudioClient audioClient = await voiceChannel.ConnectAsync(selfDeaf: true);
|
||||||
|
|
||||||
// audioClient.Disconnected += (ex) => Stop(guildId);
|
|
||||||
audioClient.StreamDestroyed += (ex) => Stop(guildId);
|
|
||||||
|
|
||||||
conn.AudioClient = audioClient;
|
conn.AudioClient = audioClient;
|
||||||
conn.AudioChannel = voiceChannel;
|
conn.AudioChannel = voiceChannel;
|
||||||
|
|
||||||
@ -45,15 +43,23 @@ namespace Kasbot.Services
|
|||||||
Search = arguments,
|
Search = arguments,
|
||||||
Name = ""
|
Name = ""
|
||||||
};
|
};
|
||||||
|
var guildId = Context.Guild.Id;
|
||||||
|
var userVoiceChannel = (Context.User as IVoiceState).VoiceChannel;
|
||||||
|
|
||||||
if (Clients.TryGetValue(Context.Guild.Id, out var conn))
|
if (Clients.TryGetValue(guildId, out var conn))
|
||||||
{
|
{
|
||||||
await Enqueue(Context.Guild.Id, conn, media);
|
if (conn.AudioChannel.Id != userVoiceChannel.Id)
|
||||||
return;
|
{
|
||||||
|
await Stop(guildId);
|
||||||
|
conn = await CreateConnection(guildId, userVoiceChannel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
conn = await CreateConnection(guildId, userVoiceChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
conn = await CreateConnection(Context.Guild.Id, (Context.User as IVoiceState).VoiceChannel);
|
await Enqueue(guildId, conn, media);
|
||||||
await Enqueue(Context.Guild.Id, conn, media);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task Enqueue(ulong guildId, Connection conn, Media media)
|
private async Task Enqueue(ulong guildId, Connection conn, Media media)
|
||||||
@ -256,7 +262,7 @@ namespace Kasbot.Services
|
|||||||
|
|
||||||
var media = Clients[guildId];
|
var media = Clients[guildId];
|
||||||
|
|
||||||
foreach (var v in media.Queue.Skip(1))
|
foreach (var v in media.Queue.Skip(0))
|
||||||
{
|
{
|
||||||
await v.PlayMessage.TryDeleteAsync();
|
await v.PlayMessage.TryDeleteAsync();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user