slshx
slshx copied to clipboard
Message not ephemeral in function generators
TL;DR :
Messages are not set as ephemeral when deferring response using yield in function generators
Info:
I need to perform an async request thus I use function generator to defer the discord response until my network operations are complete , To do so I used function generators to yield discord then return proper response after the network operation.
Using yield
causes discord message to NOT be ephemeral and thus visible to everyone . I tried both <Message>
and returning Object with content + flags: 64
Demo command handler:
function beepGen(): CommandHandler<Env> {
useDescription("Send a boop");
return async function* (interaction, env, ctx) {
// Remove yield below and message will be ephemeral as expected
yield;
return <Message ephemeral>🤖 Boop from slshx 🤖</Message>;
};
}
Expected:
Message response for above function to be ephemeral and only visible to invoker of discord command
Related
https://github.com/discordjs/discord.js/issues/5702
Hey! 👋 Thanks for reporting this. From that related issue it looks like this is an API limitation. I wonder if it's possible to return flags here though: https://github.com/mrbbot/slshx/blob/77c5d8c466843232da8caa1001c032f25874488c/src/interactions/response.ts#L48-L51 Could maybe do something like:
function beepGen(): CommandHandler<Env> {
useDescription("Send a boop");
return async function* (interaction, env, ctx) {
// Remove yield below and message will be ephemeral as expected
yield $ephemeral;
return <Message ephemeral>🤖 Boop from slshx 🤖</Message>;
};
}
As far as I understand from the referred issue , the ephemeral state cannot be changed by the follow up message but only the content , thus to make a message ephemeral , the 1st instance of it should be passed flag ephemeral
I think this could be done by passing the flags
to data
property of APIInteractionResponseDeferredChannelMessageWithSource
export interface APIInteractionResponseDeferredChannelMessageWithSource {
type: InteractionResponseType.DeferredChannelMessageWithSource;
data?: Pick<APIInteractionResponseCallbackData, 'flags'>;
}
https://github.com/discordjs/discord-api-types/blob/8e87b3e1ce35201503623839602c44fe2a52a27b/payloads/v9/_interactions/responses.ts#L48-L51