Deleting Buttons
Hello,
I have a chat input command which sends a confirmation embed (this contains a confirm and deny button), which this is part of the ChatInputCommandInteraction
I have the confirm button handler in my "interaction-handlers" directory which handles the button click. On the button click, I want to delete the action row from the ChatInputCommandInteraction, however, I only have access to the ButtonInteraction within the button handler which is a separate interaction.
What is the cleanest / most efficient way to achieve this?
12 Replies
You should be able to pull the message containing the clicked button from the ButtonInteraction and then edit the message to remove any components you no longer want.
docs: https://old.discordjs.dev/#/docs/discord.js/main/class/ButtonInteraction?scrollTo=message
I don't have a
Message
since I'm using ChatInputCommandInteraction#reply
which returns an InteractionResponse
So I get an Unknown Message
error from the API when trying to edit interaction.message
I think I'm missing something here. Are you trying to remove the buttons in the handler for the ChatInputCommandInteraction or the ButtonInteraction?
Wait, I just did a console log and it shows a
message
indeeds exist, yet I am getting an API error
from the logger ^
my code snippet relevant to the log
but as you can see in the log, the message clearly exists, but when trying to edit it, it's an unknown message Thats weird. Is it an ephemeral message? I think there's some weirdness with editing those
So the embed is originally created in the ChatInputCommandInteraction with the buttons
then the code above is the ButtonHandler / ButtonInteraction
its ephemeral yeah
I'm not sure if ephemeral messages can be edited. You could probably delete and resend it without the buttons but there might be a better option that I don't know about.
Hmmm, fair enough, thank you for the help
I won't mark as resolved just yet, just in case Favna jumps in with a better solution or something
Oh maybe try setting ephemeral to true when you edit the message
It's not a property of
MessageEditOptions
It should be
https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageFlags#Ephemeral
You can probably pass in the unmodified flags bitfield from the message since you don't need to actually change anything.
So yeah, you can't edit an ephemeral message, it worked when I set it to false
So I have made a workaround for that, not how I wanted it to be but I guess that's limitations for you
Thanks again for the help