public async Task AllowUserAsync(params SocketGuildUser[] targetUsers) { await ReplyAsync(userLockedChannels.Count.ToString()); //Check if the user has locked any channels //if (userLockedChannels.ContainsKey(Context.User.Id)) //{ Console.WriteLine("Allowing User"); SocketVoiceChannel channel = userLockedChannels[Context.User.Id]; //Prepare the permissions OverwritePermissions perms = new OverwritePermissions(); perms = perms.Modify(connect: PermValue.Allow); try { foreach (var user in targetUsers) { await channel.AddPermissionOverwriteAsync(user, perms); } } catch (Exception e) { Console.WriteLine(e); } //} await Task.CompletedTask; }
public async Task LockVoiceAsync() { if (!userLockedChannels.ContainsKey(Context.User.Id)) { SocketGuildUser user = Context.Guild.GetUser(Context.User.Id); SocketVoiceChannel channel = user.VoiceChannel; userLockedChannels.Add(Context.User.Id, channel); //add them to the list Console.WriteLine("---------"); try { //Setup 2 types of permissions, 1 to allow the current users, the other to block everyone else OverwritePermissions allowedUser = new OverwritePermissions(); allowedUser = allowedUser.Modify(connect: PermValue.Allow); OverwritePermissions deniedUsers = new OverwritePermissions(); deniedUsers = deniedUsers.Modify(connect: PermValue.Deny); //Block everyone else await channel.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, deniedUsers); //find every connected voice user and add them to the list foreach (var channelUsers in channel.Users) { await channel.AddPermissionOverwriteAsync(channelUsers, allowedUser); } } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine("---------"); } await Task.CompletedTask; }