parsecer
parsecer

Reputation: 5106

Discordjs: changing button style on click, interaction.edit is not a function, Interaction has already been acknowledged, not been sent or deferred

I have embed with buttons. When buttons are clicked interactionCreate event is triggered. It used to show red message This interaction has failed, because I don't want the bot to reply in chat each time a button is clicked, so I added buttonInteraction.deferUpdate(); to prevent that.

Now the buttons work fine and the This interaction has failed doesn't appear.

However I'd like to change the style of a button that was pressed.

I tried to do

buttonInteraction.component.disabled = true; 
buttonInteraction.component.style = 3;
buttonInteraction.edit({component: buttonInteraction.component});

But I get a TypeError: interaction.edit is not a function error.

Changing it to editReply results in Error [INTERACTION_NOT_REPLIED]: The reply to this interaction has not been sent or deferred. error:

buttonInteraction.component.disabled = true;
buttonInteraction.component.style = 3;
buttonInteraction.editReply({component: buttonInteraction.component});

Changing it to

buttonInteraction.update({component: buttonInteraction.component});

causes DiscordAPIError: Interaction has already been acknowledged. error

I'm not sure what is wrong and would appreciate any help!

Upvotes: 1

Views: 877

Answers (2)

parsecer
parsecer

Reputation: 5106

I worked it out:

In method that reacts to event:

buttonInteraction.component.disabled = true;
buttonInteraction.component.style = "SUCCESS";
let allComponents = buttonInteraction.message.components;
await buttonInteraction.update({components: allComponents});
buttonInteraction.editReply();

And I removed .deferUpdate from the client.on("interactionCreate")

Some notes: I only managed to make a clicked button to update by passing all components on that message to the .update method. Couldn't figure out how to update that very button individually.

Upvotes: 0

T1ranexDev
T1ranexDev

Reputation: 57

You might try using:

buttonInteraction.message.edit({component: buttonInteraction.component});

Upvotes: 1

Related Questions