#Editing message buttons

1 messages · Page 1 of 1 (latest)

little orchid
#

Making a thread so others aren't as confused by who you're talking to :P

#

I also realized I'm braindead and both errors are not occurring at the same time.

This code produces this error:

async function confirmPrompt(message, time) {
    const confirmButtons = new MessageActionRow()
    .addComponents(
        new MessageButton()
            .setCustomId('confirm')
            .setLabel('Confirm')
            .setStyle('SUCCESS')
            .setDisabled(true),
        new MessageButton()
            .setCustomId('cancel')
            .setLabel('Cancel')
            .setStyle('DANGER')
            .setDisabled(true)
    );
    
    // No need to check for author because the message is ephemeral
    return await message.awaitMessageComponent({
        filter: (i) => i.customId == "confirm" || i.customId == "cancel",
        time: time,
        componentType: 'BUTTON'
    }).then((interaction) => {
        interaction.update({
            components: [ confirmButtons ]
        });

        if (interaction.customId == "confirm") {
            return "confirm";
        } else {
            return "cancel";
        }
    })
    .catch(() => {
        message.edit({
            components: [ confirmButtons ]
        });
        return "cancel";
    })
}
DiscordAPIError: Unknown Message
    at RequestHandler.execute (G:\Code\Debugging\Discord\TLGOadmin\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (G:\Code\Debugging\Discord\TLGOadmin\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
    at async MessageManager.edit (G:\Code\Debugging\Discord\TLGOadmin\node_modules\discord.js\src\managers\MessageManager.js:132:15) {
  method: 'patch',
  path: '/channels/929000047029420034/messages/931716547716726805',
  code: 10008,
  httpStatus: 404,
  requestData: {
      avatar_url: undefined,
      allowed_mentions: undefined,
      flags: 64,
      message_reference: undefined,
      attachments: undefined,
      sticker_ids: undefined
    },
    files: []
  }
}
#

Changing the

.catch(() => {
    message.edit({
        components: [ confirmButtons ]
    });
    return "cancel";
})

to

.catch((message) => {
    message.edit({
        components: [ confirmButtons ]
    });
    return "cancel";
})

throws

TypeError: message.edit is not a function
    at G:\Code\Debugging\Discord\TLGOadmin\commands\ban.js:142:17
    at async confirmPrompt (G:\Code\Debugging\Discord\TLGOadmin\commands\ban.js:126:12)
    at async G:\Code\Debugging\Discord\TLGOadmin\commands\ban.js:66:34
    at async Object.execute (G:\Code\Debugging\Discord\TLGOadmin\commands\ban.js:56:13)
    at async Client.<anonymous> (G:\Code\Debugging\Discord\TLGOadmin\index.js:40:3)
G:\Code\Debugging\Discord\TLGOadmin\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:90
    if (this.deferred || this.replied) throw new Error('INTERACTION_ALREADY_REPLIED');
                                             ^

Error [INTERACTION_ALREADY_REPLIED]: The reply to this interaction has already been sent or deferred.
    at CommandInteraction.reply (G:\Code\Debugging\Discord\TLGOadmin\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:90:46)
    at Client.<anonymous> (G:\Code\Debugging\Discord\TLGOadmin\index.js:43:22) {
  [Symbol(code)]: 'INTERACTION_ALREADY_REPLIED'
}
gusty cedar
#

dapi error stack traces are stupid as always

#

the second way isn't valid anyway

#

so you can ignore it for now

little orchid
#

👍

gusty cedar
#

can you log message in the catch please

little orchid
gusty cedar
little orchid
#

My message collector is working though, so it's definitely defined

gusty cedar
#

so you wanna tell me that it logged empty

little orchid
#

Precisely!

#

I suppose I could in theory just edit the buttons outside of the function (although i'd rather do it inside)...

gusty cedar
#

I'm honest

#

I dont get it

#

it works when I test it

little orchid
#

The only difference between us is mine is getting called by a slash command, and the message that is fetched is a reply to it. (and it is ephemeral)

#

I don't see why any of this should affect it though

gusty cedar
#

did you just say

#

its ephemeral meguFaceReverse

little orchid
#

yes

#

you can edit ephemeral messages right?

#

I mean, if I do click a button it does work

#

in the .then()

#

so editing buttons on an ephemeral message is possible

gusty cedar
#

updating using an interaction is a different thing

little orchid
#

I thought you could edit them, just not delete them...

#

So...

gusty cedar
#

you can edit them, through an interaction

#

not through a message

little orchid
#

with this in mind

#

is it not possible to disable these buttons?

gusty cedar
#

if its an ephemeral reply and you dont click the button, no

little orchid
#

I see

#

Well, that's an oof

#

Thanks for the help

gusty cedar
#

wait

#

is it a followup or the initial reply

little orchid
#

the message the buttons are attached to?

gusty cedar
#

yes

little orchid
#

initial reply

gusty cedar
#

then you can use the interaction

#

interaction.editReply()

little orchid
#

Will try

#

omg it works

#

Thank you so much

#

I've spent the last two hours working on this 🤯

gusty cedar
#

yk, you could have told me that with the ephemeral reply and slash command first KEK

little orchid
#

in a comment for the code i posted was // No need to check for author because the message is ephemeral

#

I thought you knew :P

#

I will be more explicit next time lol

gusty cedar
#

well how should I know, all I see is a variable called "message" xD

little orchid
#

Fair enough

#

Have a good night!

#

Thanks again!

gusty cedar
#

you too

#

I will go take a huge shit after this

#

and then sleep JarJarYes

little orchid
#

lmao