Advertisement
Intreipd

Untitled

Oct 16th, 2017
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. [Command("help")]
  2.         [Remarks("List all available commands")]
  3.         public async Task Help()
  4.         {
  5.             // Send the message via DM to not flood the chat
  6.             var dmChannel = await Context.User.GetOrCreateDMChannelAsync();
  7.  
  8.             if (Context.Channel != dmChannel)
  9.                 await Context.Message.DeleteAsync(); // Only delete the command if we're not in a DM
  10.  
  11.             string prefix = BotConfig.Load().Prefix;
  12.             var builder = new EmbedBuilder() // Post the commands within an embedded message
  13.             {
  14.                 Color = new Color(255, 0, 0),
  15.                 Description = "These are the commands you can use:"
  16.             };
  17.  
  18.             // Loop through each of the modules loaded in the CommandService
  19.             foreach (var module in _commands.Modules)
  20.             {
  21.                 string description = null;
  22.                 foreach (var cmd in module.Commands)
  23.                 {
  24.                     // Check if each command passes
  25.                     var result = cmd.CheckPreconditionsAsync(Context);
  26.                     if (result.IsCompleted)
  27.                         // If they do pass, add the first alias (the actual name of the command) to the description tag of the embed
  28.                         description += $"{prefix}{cmd.Aliases[0]}\n";
  29.                 }
  30.  
  31.                 if (!string.IsNullOrWhiteSpace(description))
  32.                 {
  33.                     builder.AddField(x =>
  34.                     {
  35.                         x.Name = module.Name;
  36.                         x.Value = description;
  37.                         x.IsInline = false;
  38.                     });
  39.                 }
  40.             }
  41.  
  42.             await dmChannel.SendMessageAsync("", false, builder.Build());
  43.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement