internal static async Task Migration_CreateTextChannels(DiscordRestClient client, RestGuild guild) { var text1 = await guild.GetDefaultChannelAsync(); var text2 = await guild.CreateTextChannelAsync("text2"); var text3 = await guild.CreateTextChannelAsync("text3"); var text4 = await guild.CreateTextChannelAsync("text4"); var text5 = await guild.CreateTextChannelAsync("text5"); // create a channel category var cat1 = await guild.CreateCategoryChannelAsync("cat1"); if (text1 == null) { // the guild did not have a default channel, so make a new one text1 = await guild.CreateTextChannelAsync("default"); } //Modify #general await text1.ModifyAsync(x => { x.Name = "text1"; x.Position = 1; x.Topic = "Topic1"; x.CategoryId = cat1.Id; }); await text2.ModifyAsync(x => { x.Position = 2; x.CategoryId = cat1.Id; }); await text3.ModifyAsync(x => { x.Topic = "Topic2"; }); await text4.ModifyAsync(x => { x.Position = 3; x.Topic = "Topic2"; }); await text5.ModifyAsync(x => { }); CheckTextChannels(guild, text1, text2, text3, text4, text5); }
private async Task <RestTextChannel> CreateTextChannelAsync(RestGuild guild, string courseName, RequestOptions requestOptions, ulong roleId) { // prevent duplicate under this category foreach (var channel in await guild.GetChannelsAsync()) { if (channel.Name.Equals(courseName, StringComparison.OrdinalIgnoreCase) && channel is RestCategoryChannel restCategory && restCategory.Id == CategoryId) { // there's a match under this category return(null); } } var category = await guild.GetChannelAsync(CategoryId); var overwriteList = new List <Overwrite>(); overwriteList.AddRange(category.PermissionOverwrites); overwriteList.Add(new Overwrite(guild.EveryoneRole.Id, PermissionTarget.Role, new Discord.OverwritePermissions(viewChannel: Discord.PermValue.Deny))); overwriteList.Add(new Overwrite(roleId, PermissionTarget.Role, new Discord.OverwritePermissions(viewChannel: Discord.PermValue.Allow))); var result = await guild.CreateTextChannelAsync(courseName, options => { options.CategoryId = CategoryId; options.Topic = $"Course channel for {courseName}"; options.PermissionOverwrites = overwriteList; }, options : requestOptions); return(result); }
internal static async Task Migration_CreateTextChannels(DiscordRestClient client, RestGuild guild) { var text1 = await guild.GetDefaultChannelAsync(); var text2 = await guild.CreateTextChannelAsync("text2"); var text3 = await guild.CreateTextChannelAsync("text3"); var text4 = await guild.CreateTextChannelAsync("text4"); var text5 = await guild.CreateTextChannelAsync("text5"); //Modify #general await text1.ModifyAsync(x => { x.Name = "text1"; x.Position = 1; x.Topic = "Topic1"; }); await text2.ModifyAsync(x => { x.Position = 2; }); await text3.ModifyAsync(x => { x.Topic = "Topic2"; }); await text4.ModifyAsync(x => { x.Position = 3; x.Topic = "Topic2"; }); await text5.ModifyAsync(x => { }); CheckTextChannels(guild, text1, text2, text3, text4, text5); }