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.

MessageCommandModule.cs 1.2 KiB

123456789101112131415161718192021222324252627282930
  1. using Discord;
  2. using Discord.Interactions;
  3. using Discord.WebSocket;
  4. using System.Threading.Tasks;
  5. namespace InteractionFramework.Modules
  6. {
  7. // A transient module for executing commands. This module will NOT keep any information after the command is executed.
  8. internal class MessageCommandModule : InteractionModuleBase<SocketInteractionContext<SocketMessageCommand>>
  9. {
  10. // Pins a message in the channel it is in.
  11. [MessageCommand("pin")]
  12. public async Task PinMessageAsync(IMessage message)
  13. {
  14. // make a safety cast to check if the message is ISystem- or IUserMessage
  15. if (message is not IUserMessage userMessage)
  16. await RespondAsync(text: ":x: You cant pin system messages!");
  17. // if the pins in this channel are equal to or above 50, no more messages can be pinned.
  18. else if ((await Context.Channel.GetPinnedMessagesAsync()).Count >= 50)
  19. await RespondAsync(text: ":x: You cant pin any more messages, the max has already been reached in this channel!");
  20. else
  21. {
  22. await userMessage.PinAsync();
  23. await RespondAsync(":white_check_mark: Successfully pinned message!");
  24. }
  25. }
  26. }
  27. }