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.

05-responding-ephemerally.md 1.3 KiB

1234567891011121314151617181920212223242526272829
  1. # Responding ephemerally
  2. What is an ephemeral response? Basically, only the user who executed the command can see the result of it. In labs this is pretty simple to do.
  3. First, we need to talk about `AlwaysAcknowledgeInteractions` in the discord config. `AlwaysAcknowledgeInteractions` will always acknowledge the message non-ephemerally, meaning any follow-up messages or responses will also be non-ephemeral. If you set `AlwaysAcknowledgeInteractions` to false, you can acknowledge interactions yourself with the ephemeral field set to your discretion.
  4. **Note**: You don't have to run arg.AcknowledgeAsync() to capture the interaction, you can use arg.RespondAsync with a message to capture it, this also follows the ephemeral rule.
  5. Let's start by changing our client config.
  6. ```cs
  7. client = new DiscordSocketClient(new DiscordSocketConfig()
  8. {
  9. // Add this!
  10. AlwaysAcknowledgeInteractions = false,
  11. });
  12. ```
  13. When responding with either `FollowupAsync` or `RespondAsync` you can pass in an `ephemeral` property. When setting it to true it will respond ephemerally, false and it will respond non-ephemerally.
  14. Let's use this in our list role command.
  15. ```cs
  16. await command.RespondAsync(embed: embedBuiler.Build(), ephemeral: true);
  17. ```
  18. Running the command now only shows the message to us!
  19. ![ephemeral command](images/ephemeral1.png)