Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Message not ephemeral in function generators #7

Open
solaris7x opened this issue Mar 22, 2022 · 2 comments
Open

Message not ephemeral in function generators #7

solaris7x opened this issue Mar 22, 2022 · 2 comments

Comments

@solaris7x
Copy link

solaris7x commented Mar 22, 2022

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

discordjs/discord.js#5702

@mrbbot
Copy link
Owner

mrbbot commented Mar 22, 2022

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:

return jsonResponse<
| APIInteractionResponseDeferredChannelMessageWithSource
| APIInteractionResponseDeferredMessageUpdate
>({ type: resType });

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>;
  };
}

@solaris7x
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants