#How to use Ephemeral in Slash Command?

1 messages · Page 1 of 1 (latest)

torpid jay
#

For the life of me I can't figure out what do you call these type of messages or where in the library I can find them. I want user to use a command and then in the same channel they get a response but I want the response to be one of those when its hidden from other users and they can click on dismiss to get rid of it.

Here is an example

Edit: figured out the name: Ephemeral. But still having problems getting it to work on a slash command, please see my examples below.

cinder sparrowBOT
#
Automated suggestion: You don't have the Message Content Intent enabled

As of September 1st 2022, Discord started requiring message content intent for bots that want to read message content. This is a privileged intent!

If your bot has under 100 guilds, all you have to do is flip the switch in the developer dashboard (over at https://discord.com/developers/applications, also see the image) and then specifying the intent in your DiscordConfiguration (see the code example)
If your bot has over 100 guilds, you'll need approval from Discord's end.

Even though you can just use this to get away with it, it is recommended by Discord to use Slash Commands whenever possible, so look into that if you can (Slash Commands Documentation)

More info:
https://support-dev.discord.com/hc/en-us/articles/4404772028055-Message-Content-Privileged-Intent-FAQ

Code Example:

DiscordConfiguration config = new() {
    // ...
    // If you do not set this, your bot will fail to start with the error code: "Disallowed intent(s)"
    Intents = DiscordIntents.AllUnprivileged | DiscordIntents.MessageContents,
    // ...
}
torpid jay
#

Here is what I tried:

[SlashCommand("HowToUse", "How to use the bot")]
        public async Task AddMessageReaction(InteractionContext context)
        {
            await context.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);

            var builder = new DiscordFollowupMessageBuilder().AsEphemeral();
            builder.WithContent("Some Test");

            await context.Interaction.CreateFollowupMessageAsync(builder);

        }
#

If I try setting InteractionResponseType.DeferredMessageUpdate then the bot just hangs.

#

that is what I get

torpid jay
#

How to use Ephemeral in Slash Command?

steel rover
#

I've never used followup messages but I can suggest something. Instead of using ctx.CreateResponseAsync, use ctx.DeferAsync()
DeferAsync has a parameter for ephemeral messages and its default value is false. You can simply do ctx.DeferAsync(true) and use ctx.EditResponseAsync() later on

torpid jay