private async Task <(RestRole role, RestCategoryChannel category, RestTextChannel text, RestVoiceChannel voice)> CreateGroup(int groupNumber) { string name = string.Format(_groupConfig.GroupChannelNameTemplate, groupNumber); RestRole role = await Context.Guild.CreateRoleAsync(name, GuildPermissions.None, _roleColors[(groupNumber - 1) % _roleColors.Count], // groupNumber is 1-indexed isMentionable : false, isHoisted : true); // Create group-category which only 'role' can see and join RestCategoryChannel category = await Context.Guild.CreateCategoryChannelAsync(name); OverwritePermissions groupPermission = new OverwritePermissions(viewChannel: PermValue.Allow, connect: PermValue.Allow); await category.AddPermissionOverwriteAsync(role, groupPermission); // The bot needs those permissions as well otherwise it can't delete the channel later on. Alternatively you could add 'role' to the bot. await category.AddPermissionOverwriteAsync(Context.Client.CurrentUser, groupPermission); OverwritePermissions everyonePermission = new OverwritePermissions(viewChannel: PermValue.Deny, connect: PermValue.Deny); await category.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, everyonePermission); // Add one text and one voice channel Action <GuildChannelProperties> assignCategoryId = c => c.CategoryId = category.Id; RestTextChannel text = await Context.Guild.CreateTextChannelAsync(name, assignCategoryId); RestVoiceChannel voice = await Context.Guild.CreateVoiceChannelAsync(name, assignCategoryId); return(role, category, text, voice); }
public async Task CreateSection() { GuildBson guild = await Database.LoadRecordsByGuildId(Context.Guild.Id); RestCategoryChannel categoryChannel = await Context.Guild.CreateCategoryChannelAsync("Auditor"); await categoryChannel.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, OverwritePermissions.DenyAll(categoryChannel)); foreach ((string name, ulong?channel) in GetSettingStates(guild)) { if (channel == null) { continue; } RestTextChannel textChannel = await Context.Guild.CreateTextChannelAsync(name.Replace("Event", ""), o => o.CategoryId = categoryChannel.Id); guild.GetType().GetProperty(name)?.SetValue(guild, textChannel.Id); } guild.CategoryId = categoryChannel.Id; await Database.UpdateGuild(guild); await SendSuccessAsync("Created Auditor sections, please move to a more convenient place."); }
private static async Task AddCategoryWithChannels(SocketGuild guild, IRole memberRole, string categoryName, int position) { RestCategoryChannel category = await guild.CreateCategoryChannelAsync(categoryName, properties => properties.Position = position); await category.AddPermissionOverwriteAsync(guild.EveryoneRole, OverwritePermissions.InheritAll); await category.AddPermissionOverwriteAsync(memberRole, OverwritePermissions.InheritAll); //Text chat RestTextChannel chat = await guild.CreateTextChannelAsync(categoryName.ToLower(), properties => properties.CategoryId = category.Id); await chat.SyncPermissionsAsync(); //Auto VC chat RestVoiceChannel autoVcChat = await AutoVCChannelCreator.CreateAutoVCChannel(guild, categoryName); await autoVcChat.ModifyAsync(properties => properties.CategoryId = category.Id); await autoVcChat.SyncPermissionsAsync(); }