discord.net僵尸程序加入并立即退出语音聊天

时间:2020-04-29 09:53:34

标签: c# discord discord.net

我制作了一个机器人,该机器人在大多数情况下都可以按预期工作,但是在尝试使其加入语音通道时,如果有人在我要求其加入的语音聊天中,则会立即断开连接但是,如果语音聊天中没有其他人,则它可以毫无问题地加入并连接,那么用户可以加入该频道,并且它将保持连接状态。有解决办法吗?

这是我正在使用的代码:

public async Task Join(IAudioChannel channel = null) //SocketUser user, SocketVoiceState state1, SocketVoiceState state2)
{

    //  IAudioClient audioClient = await (Context.User as IVoiceState).VoiceChannel.ConnectAsync();

    var UserCheck = Context.Guild.GetUser(Context.User.Id);
    channel ? ?=(Context.Message.Author as IGuildUser) ? .VoiceChannel;
    var roleCheck = Context.Guild.Roles.FirstOrDefault(x = >x.Name == "DJ");

    if (UserCheck.Roles.Contains(roleCheck)) {
        if (channel == null) {
            await Context.Message.DeleteAsync();
            await ReplyAsync("You need to be in a voice channel, or pass one as an argument.");
            return;
        }
        else {

            // IAudioClient audioClient = await channel.ConnectAsync();
            IAudioClient audioClient = await channel.ConnectAsync();

        }
    }
    else {
        await Context.Message.DeleteAsync();
        await ReplyAsync("Insufficient Permissions");
    }
}

当其他人在聊天中时,此功能可以以其他任何方式起作用。有人可以帮忙吗?

0 个答案:

没有答案