gatekeeper icon indicating copy to clipboard operation
gatekeeper copied to clipboard

Ephemeral replies can't be edited

Open felds opened this issue 3 years ago • 2 comments

Currently, context.ephemeralReply returns void because:

This does not return a reply handle; ephemeral replies can't be updated or deleted manually — interaction-context.ts:52

However, I did a little testing and it seems to update just like regular replies. Maybe there was an API update since then?

Here's my test code:

import assert from "assert";
import { Client, Intents } from "discord.js";
import { setTimeout } from "timers/promises";
import { GUILD_ID, TOKEN } from "../src/config";

console.clear();

const client = new Client({
  intents: [Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILDS],
});
client.login(TOKEN);

client.on("ready", async () => {
  const acm = client.application?.commands;
  assert(acm);

  const cmd = await acm.create(
    {
      type: "CHAT_INPUT",
      name: "edit-reply",
      description: "Editind ephemeral reply",
    },
    GUILD_ID!,
  );
});

client.on("interactionCreate", async (interaction) => {
  assert(interaction.isApplicationCommand());

  await interaction.deferReply({ ephemeral: true });

  await setTimeout(1_000);

  await interaction.editReply({
    embeds: [{ color: "RED", description: "First reply" }],
    // prettier-ignore
    components: [
      {type: "ACTION_ROW", components: [
        {type: "BUTTON", disabled: true, style: "PRIMARY", label: "Am I enabled?", customId: "btn"},
      ]},
    ],
  });

  await setTimeout(1_000);

  await interaction.editReply({
    embeds: [{ color: "AQUA", description: "Edited reply" }],
    // prettier-ignore
    components: [
      {type: "ACTION_ROW", components: [
        {type: "BUTTON", disabled: false, style: "PRIMARY", label: "I'm enabled!", customId: "btn"},
      ]},
    ],
  });
});

felds avatar Dec 14 '21 15:12 felds

Hm, my memory of the details on this is a bit fuzzy, but here's what I recall:

  • Ephemeral messages can't be edited via message.edit, as in, the DJS Message
  • Attempting to call editReply on an interaction that happened via a followup will result in the first original reply getting edited
  • Ephemeral followups can't be edited at all

It's these points that lead me to not supporting arbitrary edits on ephems at all. I wanted replies and followups to have feature parity and behave predictably in the same way; this behavior breaks that goal. But if that's changed since then, and ephemeral followups and replies can both be predictably refreshed arbitrarily, then I'd consider giving ephems a handle just for editing.

itsMapleLeaf avatar Dec 14 '21 16:12 itsMapleLeaf

I'll take a look on the current state of those and report back back to you.

felds avatar Dec 14 '21 17:12 felds