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.

SlashCommandModule.cs 1.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Discord;
  2. using Discord.Interactions;
  3. using Discord.WebSocket;
  4. using System;
  5. using System.Threading.Tasks;
  6. namespace InteractionFramework.Modules
  7. {
  8. public enum Hobby
  9. {
  10. Gaming,
  11. Art,
  12. Reading
  13. }
  14. // A transient module for executing commands. This module will NOT keep any information after the command is executed.
  15. class SlashCommandModule : InteractionModuleBase<SocketInteractionContext<SocketSlashCommand>>
  16. {
  17. // Will be called before execution. Here you can populate several entities you may want to retrieve before executing a command.
  18. // I.E. database objects
  19. public override void BeforeExecute(ICommandInfo command)
  20. {
  21. // Anything
  22. throw new NotImplementedException();
  23. }
  24. // Will be called after execution
  25. public override void AfterExecute(ICommandInfo command)
  26. {
  27. // Anything
  28. throw new NotImplementedException();
  29. }
  30. [SlashCommand("ping", "Pings the bot and returns its latency.")]
  31. public async Task GreetUserAsync()
  32. => await RespondAsync(text: $":ping_pong: It took me {Context.Client.Latency}ms to respond to you!", ephemeral: true);
  33. [SlashCommand("hobby", "Choose your hobby from the list!")]
  34. public async Task ChooseAsync(Hobby hobby)
  35. => await RespondAsync(text: $":thumbsup: Your hobby is: {hobby}.");
  36. [SlashCommand("bitrate", "Gets the bitrate of a specific voice channel.")]
  37. public async Task GetBitrateAsync([ChannelTypes(ChannelType.Voice, ChannelType.Stage)] IChannel channel)
  38. {
  39. var voiceChannel = channel as IVoiceChannel;
  40. await RespondAsync(text: $"This voice channel has a bitrate of {voiceChannel.Bitrate}");
  41. }
  42. }
  43. }