Discord.Net 中的临时语音通道
Temporary Voice Channels in Discord.Net
我在 C# 中有以下工作代码并使用 Discord.Net 但我不知道我需要做什么,删除
频道内没有用户时临时创建的频道。 我知道如何删除一个频道,但我不知道如何检查旧频道是否是临时创建的频道。
我需要检查旧频道是否是临时创建的频道,并在频道中没有用户但只有这个频道而不是其他每个频道时删除它。
这是我目前的工作代码
_client.UserVoiceStateUpdated += HandleVoiceState;
}
public async Task HandleVoiceState(SocketUser user, SocketVoiceState before, SocketVoiceState after)
{
Console.WriteLine($"VoiceStateUpdate: {user} - {before.VoiceChannel?.Name ?? "null"} -> {after.VoiceChannel?.Name ?? "null"}");
//needs await
if (user is SocketGuildUser socketGuildUser)
{
var server = socketGuildUser.Guild;
var categoryId = server.CategoryChannels.FirstOrDefault(category => category.Name.Equals(" Staff "))?.Id;
if (socketGuildUser.VoiceState?.VoiceChannel.Id == 856855859001557012)
{
var voiceChannel = await server.CreateVoiceChannelAsync(socketGuildUser.Username, prop => prop.CategoryId = categoryId);
Console.WriteLine(voiceChannel.Id);
await socketGuildUser.ModifyAsync(x =>
{
x.Channel = Optional.Create(voiceChannel as IVoiceChannel);
});
}
}
}
var usersVoiceChannel = (socketGuildUser as IVoiceState).VoiceChannel;
if (usersVoiceChannel == null)
{
if ((after.VoiceChannel != before.VoiceChannel)
&& before.VoiceChannel.Category.Id.Equals(autocreatecategoryid)
&& before.VoiceChannel.Users.Count == 0
&& !before.VoiceChannel.Id.Equals(autocreateid))
{
await before.VoiceChannel.DeleteAsync();
}
}else{
if (!(before.VoiceChannel == null)
&& before.VoiceChannel.Category.Id.Equals(autocreatecategoryid)
&& before.VoiceChannel.Users.Count == 0
&& !before.VoiceChannel.Id.Equals(autocreateid))
{
await before.VoiceChannel.DeleteAsync();
}
}
}
我在 C# 中有以下工作代码并使用 Discord.Net 但我不知道我需要做什么,删除 频道内没有用户时临时创建的频道。 我知道如何删除一个频道,但我不知道如何检查旧频道是否是临时创建的频道。 我需要检查旧频道是否是临时创建的频道,并在频道中没有用户但只有这个频道而不是其他每个频道时删除它。
这是我目前的工作代码
_client.UserVoiceStateUpdated += HandleVoiceState;
}
public async Task HandleVoiceState(SocketUser user, SocketVoiceState before, SocketVoiceState after)
{
Console.WriteLine($"VoiceStateUpdate: {user} - {before.VoiceChannel?.Name ?? "null"} -> {after.VoiceChannel?.Name ?? "null"}");
//needs await
if (user is SocketGuildUser socketGuildUser)
{
var server = socketGuildUser.Guild;
var categoryId = server.CategoryChannels.FirstOrDefault(category => category.Name.Equals(" Staff "))?.Id;
if (socketGuildUser.VoiceState?.VoiceChannel.Id == 856855859001557012)
{
var voiceChannel = await server.CreateVoiceChannelAsync(socketGuildUser.Username, prop => prop.CategoryId = categoryId);
Console.WriteLine(voiceChannel.Id);
await socketGuildUser.ModifyAsync(x =>
{
x.Channel = Optional.Create(voiceChannel as IVoiceChannel);
});
}
}
}
var usersVoiceChannel = (socketGuildUser as IVoiceState).VoiceChannel;
if (usersVoiceChannel == null)
{
if ((after.VoiceChannel != before.VoiceChannel)
&& before.VoiceChannel.Category.Id.Equals(autocreatecategoryid)
&& before.VoiceChannel.Users.Count == 0
&& !before.VoiceChannel.Id.Equals(autocreateid))
{
await before.VoiceChannel.DeleteAsync();
}
}else{
if (!(before.VoiceChannel == null)
&& before.VoiceChannel.Category.Id.Equals(autocreatecategoryid)
&& before.VoiceChannel.Users.Count == 0
&& !before.VoiceChannel.Id.Equals(autocreateid))
{
await before.VoiceChannel.DeleteAsync();
}
}
}