From a0173dcd9c6521df5663158112599d3e97fd7265 Mon Sep 17 00:00:00 2001 From: drobbins329 Date: Sun, 15 Aug 2021 17:22:37 -0400 Subject: [PATCH] Added Receive event guides --- .../receiving-context-menu-command-events.md | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 docs/guides/application-commands/context-menu-commands/receiving-context-menu-command-events.md diff --git a/docs/guides/application-commands/context-menu-commands/receiving-context-menu-command-events.md b/docs/guides/application-commands/context-menu-commands/receiving-context-menu-command-events.md new file mode 100644 index 000000000..a1492fc50 --- /dev/null +++ b/docs/guides/application-commands/context-menu-commands/receiving-context-menu-command-events.md @@ -0,0 +1,43 @@ +# Receiving Context Menu events + +User commands and Message commands have their own unique objects returned. Different from Slash commands. To get the appropriate object returned, you can use a similar method to the slash commands. + +```cs +client.InteractionCreated += InteractionCreatedHandler; + +... + +public async Task InteractionCreatedHandler(SocketInteraction arg) +{ + if ( arg.Type == InteractionType.ApplicationCommand) + Task.Run(() => ApplicationCommandHandler(arg)); +} + +public async Task ApplicationCommandHandler(SocketInteraction arg) +{ + var slashCommand = arg as SocketSlashCommand; + if(slashCommand != null) + Console.Writeline("Slash command received!") + + var userCommand = arg as SocketApplicationUserCommand; + if(userCommand != null) + { + Console.Writeline("User command received!") + // userCommand.User = User who ran command. + // userCommand.Data.Member = User who was clicked. + } + + var messageCommand = arg as SocketApplicationMessageCommand; + if(messageCommand != null) + { + Console.Writeline("Message command received!") + // messageCommand.User = User who ran command. + // messageCommand.Data.Message = Message that was clicked. + } +} +``` + +User commands return a SocketUser object, showing the user that was clicked to run the command. +Message commands return a SocketMessage object, showing the message that was clicked to run the command. + +Both return the user who ran the command, the guild (if any), channel, etc. \ No newline at end of file