You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

DevModule.cs 1.7 kB

Implemented basic parameter recognition and passing them to the method. Details: Subcommands and Subcommand groups not yet implemented, they will require for some parts of the code to be re-done. More attributes can and should be implemented, such as [Required] and [Choice(... , ...)]. Breakdown: * Rectified line endings to LF, as per the settings of the project. * Added a new command to SlashCommandService and SlashCommandServiceHelper to register the found commands to discord. * Implemented CommandRegistrationOptions that can be used to configure the behaviour on registration - what to do with old commands, and with commands that already exist with the same name. A default version exists and can be accessed with CommandRegistrationOptions.Default * Modified the sample program to reflect the changes made to the SlashCommandService and to also register a new command that tests all 6 types of CommandOptions (except subcommand and subcommand group) * At the moment all commands are registered in my test guild, because the update for global commands is not instant. See SlashCommandServiceHelper.RegisterCommands(...) or line 221. * Modified SlashCommandInfo to parse arguments given from Interaction, unde in ExecuteAsync, and added method BuilDcommand that returns SlashCommandCreationProperties - which can be registered to Discord. * Renamed in the sample project PingCommand.cs to DevModule.cs * Added custom attribute Description for the command method's parameters. * Implemented SlashParameterInfo - and extension of the OptionBuilder that implements a method name Parse - takes DataOptions and gives out a cast object to be passed to the command Delegate. Planning on doing more with it. * Moved SlashCommandBuilder.cs to the same directory structure * Moved SlashCommandModule.cs and ISlashCommandModule.cs to its own folder.
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Discord.Commands;
  2. using Discord.Commands.SlashCommands.Types;
  3. using Discord.SlashCommands;
  4. using Discord.WebSocket;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace SlashCommandsExample.Modules
  10. {
  11. public class DevModule : SlashCommandModule<SocketInteraction>
  12. {
  13. [SlashCommand("ping", "Ping the bot to see if it's alive!")]
  14. public async Task PingAsync()
  15. {
  16. await Reply(":white_check_mark: **Bot Online**");
  17. }
  18. [SlashCommand("echo", "I'll repeate everything you said to me, word for word.")]
  19. public async Task EchoAsync([Description("The message you want repetead")]string message)
  20. {
  21. await Reply($"{Interaction.Member?.Nickname ?? Interaction.Member?.Username} told me to say this: \r\n{message}");
  22. }
  23. [SlashCommand("overload","Just hit me with every type of data you got, man!")]
  24. public async Task OverloadAsync(
  25. bool boolean,
  26. int integer,
  27. string myString,
  28. SocketGuildChannel channel,
  29. SocketGuildUser user,
  30. SocketRole role
  31. )
  32. {
  33. await Reply($"You gave me:\r\n {boolean}, {integer}, {myString}, <#{channel?.Id}>, {user?.Mention}, {role?.Mention}");
  34. }
  35. }
  36. }
  37. /*
  38. The base way of defining a command using the regular command service:
  39. public class PingModule : ModuleBase<SocketCommandContext>
  40. {
  41. [Command("ping")]
  42. [Summary("Pong! Check if the bot is alive.")]
  43. public async Task PingAsync()
  44. {
  45. await ReplyAsync(":white_check_mark: **Bot Online**");
  46. }
  47. }
  48. */