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.

receiving-context-menu-command-events.md 1.1 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233
  1. ---
  2. uid: Guides.ContextCommands.Reveiving
  3. title: Receiving Context Commands
  4. ---
  5. # Receiving Context Menu events
  6. User commands and Message commands have their own unique event just like the other interaction types. For user commands the event is `UserCommandExecuted` and for message commands the event is `MessageCommandExecuted`.
  7. ```cs
  8. // For message commands
  9. client.MessageCommandExecuted += MessageCommandHandler;
  10. // For user commands
  11. client.UserCommandExecuted += UserCommandHandler;
  12. ...
  13. public async Task MessageCommandHandler(SocketMessageCommand arg)
  14. {
  15. Console.Writeline("Message command received!");
  16. }
  17. public async Task UserCommandHandler(SocketUserCommand arg)
  18. {
  19. Console.Writeline("User command received!");
  20. }
  21. ```
  22. User commands contain a SocketUser object called `Member` in their data class, showing the user that was clicked to run the command.
  23. Message commands contain a SocketMessage object called `Message` in their data class, showing the message that was clicked to run the command.
  24. Both return the user who ran the command, the guild (if any), channel, etc.