问题描述
我当时正在编写一个不和谐的机器人,我想制作一个脚本,如果用户加入语音通道,该机器人也将加入。我添加了以下代码:
_client.UserVoiceStateUpdated += OnVoiceStateUpdated;
private async Task OnVoiceStateUpdated(SocketUser user,SocketVoiceState state1,SocketVoiceState state2)
{
// Check if this was a non-bot user joining a voice channel
if (user.IsBot)
return;
if (state1.VoiceChannel == null && state2.VoiceChannel != null)
{
try
{
ConnectToVoice(state2.VoiceChannel).Start();
}
catch(Exception e)
{
Console.WriteLine(e);
}
}
}
private async Task ConnectToVoice(SocketVoiceChannel voiceChannel)
{
if (voiceChannel == null)
return;
Console.WriteLine($"Connecting to channel {voiceChannel.Id}");
var connection = await voiceChannel.ConnectAsync();
Console.WriteLine($"Connected to channel {voiceChannel.Id}");
}
它构建良好,当我加入频道时,该机器人随后出现,但是它很快就离开了,并且控制台给了我这个错误: system.invalidOperationException:在约定样式的任务上可能不会调用Start。
对为什么有任何想法吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)