public async Task PreviewRoleAsync( [Summary("The name of the role(s) the user wishes to preview, seperated by ','s.")] [Example("Overwatch")] [Example("Overwatch, Dota 2, Payday 2")] [Remainder] string roles) { List <IMessage> messages = new List <IMessage>(); List <string> roleNames = roles.Split(',').ToList(); for (int i = 0; i < roleNames.Count; i++) { roleNames[i] = roleNames[i].Trim(); } foreach (string rn in roleNames) { // Autocorrecting goes here. // Get the roleContainer corresponding to the role the user want to preview. SocketRole socketRole = Context.Guild.Roles.FirstOrDefault(sr => sr.Name.ToLower() == rn.ToLower()); if (socketRole != null) { // Construct preview message. string toReturn = $"\n**Name**: `{socketRole.Name}`"; toReturn += $"\n**Color Hex Code**: {Data.RGBToHexCode(socketRole.Color.R, socketRole.Color.G, socketRole.Color.B)}"; toReturn += $"\n**Color RGB**: {socketRole.Color.R}, {socketRole.Color.G}, {socketRole.Color.B}"; // Get channels associated with the role and sort them into text and voice channels. List <SocketGuildChannel> associatedChannels = Context.Guild.Channels.Where(c => c.GetPermissionOverwrite(socketRole).HasValue).ToList(); List <SocketTextChannel> textChannels = new List <SocketTextChannel>(); List <SocketVoiceChannel> voiceChannels = new List <SocketVoiceChannel>(); if (associatedChannels != null) { foreach (SocketGuildChannel sgc in associatedChannels) { if (sgc is SocketTextChannel) { textChannels.Add(sgc as SocketTextChannel); } if (sgc is SocketVoiceChannel) { voiceChannels.Add(sgc as SocketVoiceChannel); } } } // Add text and voice channels to the preview message. toReturn += "\n\n**Associated Text Channels:**"; if (textChannels.Count() > 0) { foreach (SocketTextChannel tc in textChannels) { toReturn += $"\n{tc.Name}"; } } else { toReturn += "\nNone"; } toReturn += "\n\n**Associated Voice Channels:**"; if (voiceChannels.Count() > 0) { foreach (SocketVoiceChannel vc in voiceChannels) { toReturn += $"\n{vc.Name}"; } } else { toReturn += "\nNone"; } // Add "associated privileges" (beyond @everyone) // PM preview to user. await Context.User.SendMessageAsync( embed : new EmbedBuilder() .WithColor(socketRole.Color) .WithTitle("Role Preview") .WithDescription(toReturn) .Build()); } else { messages.Add(await ReplyAsync( embed: new EmbedBuilder() .WithColor(Data.COLOR_ERROR) .WithTitle("ERROR: Role not found") .WithDescription($"Could not find a role matching the name `{rn}`.\nFor a full list of roles, use the `roles` command.") .WithAutoDeletionFooter() .Build())); } } // Return feedback message. messages.Add(await ReplyAsync( embed: new EmbedBuilder() .WithTitle("Preview(s) sent") .WithDescription("I've PMed you the role preview(s).") .WithAutoDeletionFooter() .Build())); // Delete prompt and feedback messages. await Task.Delay(Data.MESSAGE_DELETE_DELAY * 1000); await Context.Message.DeleteAsync(); foreach (var msg in messages) { await msg.DeleteAsync(); } }