I am using the package discord-modals
to create better modals with my discord bot.
When I want to reply to the SlashCommandInteraction
(actually it's the modalResponse
listening event), then I can't make the reply ephemeral. When I remove the ephemeral
bool, it works perfectly. But I don't understand why it doesn't work with a normal reply action.
await event.reply({content: `${replymsg}`, ephemeral: true});
So if I use this, I get the following error:
TypeError: Cannot read properties of undefined (reading 'EPHEMERAL')
at ModalSubmitInteraction.reply (C:\Users\david_h7tqe3i\WebstormProjects\musicbottest\node_modules\discord-modals\src\v14\interfaces\InteractionResponses.js:51:57)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Client.<anonymous> (C:\Users\david_h7tqe3i\WebstormProjects\musicbottest\src\index.js:107:9)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:384:10)
at processTicksAndRejections (node:internal/process/task_queues:85:21)
Process finished with exit code 1
And if I use the following code, it works:
await event.reply({content: `${replymsg}`});
CodePudding user response:
There is a bug in discord-modals
. It uses MessageFlags.FLAGS.EPHEMERAL
, but MessageFlags.FLAGS
is undefined
. For a quick fix, you can edit node_modules/discord-modals/src/v14/interfaces/InteractionResponses.js
and on line 51 replace
data.flags = options.ephemeral ? MessageFlags.FLAGS.EPHEMERAL : undefined;
with
data.flags = options.ephemeral ? MessageFlags.Ephemeral : undefined;
I've also opened a PR, hopefully, the maintainer will accept it soon.