discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.41k stars 3.97k forks source link

editReply on ephemeral doesn't work, but followUp works #7173

Closed eyal282 closed 2 years ago

eyal282 commented 2 years ago

Issue description

  1. Use passport as an authentication.
  2. use editReply after an under 10 second authentication which only works the first time the bot runs.
  3. Use followUp and it works ( which is bad because I cannot delete ephemeral messages )

Code sample

await passport.use(new CustomStrategy(
                async function(req, done)
                {
                    let code = req.query.code
                    let state = req.query.state

                    let lastState = await settings.get(`last-lichess-state-of-${interaction.user.id}`)

                    if(state != lastState)
                    {
                        return;
                    }

                    let body = `grant_type=authorization_code&client_id=Eyal282-Chess-ELO-Role-Bot-${jsGay.client.user.id}&redirect_uri=${myWebsite}${lichessEndOfWebsite}&code=${code}&code_verifier=${code_verifier}`

                    let response = await fetch(`https://lichess.org/api/token`, {
                    method: 'POST',
                    body: body,
                    headers: {'Content-Type': 'application/x-www-form-urlencoded' }
                    })

                    response = await response.json()

                    if(!response.access_token)
                        return;

                    let result = await fetch(`https://lichess.org/api/account`, {
                        method: 'GET',
                        headers: {'Authorization': `Bearer ${response.access_token}`}

                     }).then(response => {
                        if (response.status == 404) { // Not Found
                            return null
                        }
                        else if (response.status == 429) { // Rate Limit
                            return "Rate Limit"
                        }
                        else if (response.status == 200) { // Status OK
                            return response.json()
                        }
                    })

                    if(result?.id)
                    {
                        let userName = result.id

                        await settings.set(`lichess-account-of-${interaction.user.id}`, result.id)

                        done(null, "Success");
                    }
                })
            );      
        await jsGay.app.get(lichessEndOfWebsite,
            passport.authenticate("custom", { failureRedirect: '/fail' }),
                async function(req, res) {
                // Successful authentication, redirect home.

                res.redirect('/');

                console.log(interaction.user.id)
                await jsGay.updateProfileDataByInteraction(interaction, false)

                let userName = await settings.get(`lichess-account-of-${interaction.user.id}`)

                let testembed = new MessageEmbed()
                    .setColor('#0099ff')
                    .setDescription(`Successfully linked your [Lichess Profile](https://lichess.org/@/${userName})`)

                await interaction.editReply({ embeds: [testembed],  ephemeral: true }).catch(console.error)
                }
        );

discord.js version

13.1.0

Node.js version

16.9.1

Operating system

No response

Priority this issue should have

Low (slightly annoying)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

GUILDS, GUILD_MEMBERS, GUILD_MESSAGES, DIRECT_MESSAGES

I have tested this issue on a development release

No response

NickR69420 commented 2 years ago

Doesn't the edited reply become ephemeral or not depending on the reply?

eyal282 commented 2 years ago

Doesn't the edited reply become ephemeral or not depending on the reply?

It just does nothing, but it always works regardless of what you input. It's more for legacy forward in case some discord update breaks something.

Jiralite commented 2 years ago

So I'm trying to understand this issue and I really can't... Can you provide a minimal reproducible example and try to explain the issue in a different way?

vladfrangu commented 2 years ago

Since this issue has gone stale, I'll be closing this, if you can replicate this with a simple code sample, follow up and I'll reopen the issue!

m5136771 commented 2 years ago

I was just looking for a fix for this.. here's a bare bones example:

const { SlashCommandBuilder } = require('discord.js');
const wait = require('node:timers/promises').setTimeout;

module.exports = {
    data: new SlashCommandBuilder()
        .setName('ping')
        .setDescription('Replies with pong'),
    async execute(interaction) {
        await interaction.deferReply();
        await wait(4000);
        await interaction.editReply({ content: 'Pong!', ephemeral: true });
                await interaction.followUp({ content: 'Pong again!', ephemeral: true });
    },
};

When called, the message "Pong!" is NOT ephemeral, but the "Pong again!" is.

Jiralite commented 2 years ago

When called, the message "Pong!" is NOT ephemeral, but the "Pong again!" is.

That is the expected behaviour. There is nothing to fix here. To be clear: Discord cannot convert a regular message to an ephemeral one, which seems to be what you want to do here. It's not possible. If you wanted "Pong!" to be ephemeral, then defer ephemerally.