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
Ben
Ben11mo ago
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
b1nzee
b1nzee11mo ago
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
Ben
Ben11mo ago
I think I'm missing something here. Are you trying to remove the buttons in the handler for the ChatInputCommandInteraction or the ButtonInteraction?
b1nzee
b1nzee11mo ago
Wait, I just did a console log and it shows a message indeeds exist, yet I am getting an API error WaitWhat
5 August 2023 17:25:57 DEBUG [
ButtonInteraction {
type: 3,
id: '1137421020303720630',
applicationId: '1125398802182983700',
channelId: '1125397046002716855',
guildId: '1125397046002716852',
user: User {
id: '581235801900318741',
bot: false,
system: false,
flags: [UserFlagsBitField],
username: 'requiz',
discriminator: '0',
avatar: '221115b9e53ed0da692fc853468c4a28',
banner: undefined,
accentColor: undefined
},
member: GuildMember {
guild: [Guild],
joinedTimestamp: 1688385964645,
premiumSinceTimestamp: null,
nickname: null,
pending: false,
communicationDisabledUntilTimestamp: null,
_roles: [Array],
user: [User],
avatar: null,
flags: [GuildMemberFlagsBitField]
},
version: 1,
appPermissions: PermissionsBitField { bitfield: 281474976710655n },
memberPermissions: PermissionsBitField { bitfield: 281474976710655n },
locale: 'en-US',
guildLocale: 'en-US',
message: Message {
channelId: '1125397046002716855',
guildId: '1125397046002716852',
id: '1137421014578516069',
createdTimestamp: 1691252702136,
type: 20,
system: false,
content: '',
author: [ClientUser],
pinned: false,
tts: false,
nonce: null,
embeds: [Array],
components: [Array],
attachments: Collection(0) [Map] {},
stickers: Collection(0) [Map] {},
position: null,
roleSubscriptionData: null,
editedTimestamp: null,
reactions: [ReactionManager],
mentions: [MessageMentions],
webhookId: '1125398802182983700',
groupActivityApplication: null,
applicationId: '1125398802182983700',
activity: null,
flags: [MessageFlagsBitField],
reference: null,
interaction: [Object]
},
customId: 'confirm_verify_1',
componentType: 2,
deferred: false,
ephemeral: null,
replied: false,
webhook: InteractionWebhook { id: '1125398802182983700' }
}
]
5 August 2023 17:25:57 ERROR [
'Encountered error while handling an interaction handler run method for interaction-handler "ConfirmVerify" at path "F:\\Hosting Bot, LLC\\bot\\dist\\interaction-handlers\\buttons\\verify\\ConfirmVerify.js"',
DiscordAPIError[10008]: Unknown Message
at handleErrors (F:\Hosting Bot, LLC\bot\node_modules\@discordjs\rest\dist\index.js:640:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (F:\Hosting Bot, LLC\bot\node_modules\@discordjs\rest\dist\index.js:1021:23)
at async SequentialHandler.queueRequest (F:\Hosting Bot, LLC\bot\node_modules\@discordjs\rest\dist\index.js:862:14)
at async REST.request (F:\Hosting Bot, LLC\bot\node_modules\@discordjs\rest\dist\index.js:1387:22)
at async MessageManager.edit (F:\Hosting Bot, LLC\bot\node_modules\discord.js\src\managers\MessageManager.js:176:15)
at async ConfirmVerifyInteractionHandler.run (F:\Hosting Bot, LLC\bot\dist\interaction-handlers\buttons\verify\ConfirmVerify.js:46:9)
at async Object.fromAsync (F:\Hosting Bot, LLC\bot\node_modules\@sapphire\result\dist\index.js:613:22)
at async Promise.allSettled (index 0)
at async InteractionHandlerStore.run (F:\Hosting Bot, LLC\bot\node_modules\@sapphire\framework\dist\lib\structures\InteractionHandlerStore.js:48:21) {
requestBody: { files: [], json: [Object] },
rawError: { message: 'Unknown Message', code: 10008 },
code: 10008,
status: 404,
method: 'PATCH',
url: 'https://discord.com/api/v10/channels/1125397046002716855/messages/1137421014578516069'
}
]
5 August 2023 17:25:57 DEBUG [
ButtonInteraction {
type: 3,
id: '1137421020303720630',
applicationId: '1125398802182983700',
channelId: '1125397046002716855',
guildId: '1125397046002716852',
user: User {
id: '581235801900318741',
bot: false,
system: false,
flags: [UserFlagsBitField],
username: 'requiz',
discriminator: '0',
avatar: '221115b9e53ed0da692fc853468c4a28',
banner: undefined,
accentColor: undefined
},
member: GuildMember {
guild: [Guild],
joinedTimestamp: 1688385964645,
premiumSinceTimestamp: null,
nickname: null,
pending: false,
communicationDisabledUntilTimestamp: null,
_roles: [Array],
user: [User],
avatar: null,
flags: [GuildMemberFlagsBitField]
},
version: 1,
appPermissions: PermissionsBitField { bitfield: 281474976710655n },
memberPermissions: PermissionsBitField { bitfield: 281474976710655n },
locale: 'en-US',
guildLocale: 'en-US',
message: Message {
channelId: '1125397046002716855',
guildId: '1125397046002716852',
id: '1137421014578516069',
createdTimestamp: 1691252702136,
type: 20,
system: false,
content: '',
author: [ClientUser],
pinned: false,
tts: false,
nonce: null,
embeds: [Array],
components: [Array],
attachments: Collection(0) [Map] {},
stickers: Collection(0) [Map] {},
position: null,
roleSubscriptionData: null,
editedTimestamp: null,
reactions: [ReactionManager],
mentions: [MessageMentions],
webhookId: '1125398802182983700',
groupActivityApplication: null,
applicationId: '1125398802182983700',
activity: null,
flags: [MessageFlagsBitField],
reference: null,
interaction: [Object]
},
customId: 'confirm_verify_1',
componentType: 2,
deferred: false,
ephemeral: null,
replied: false,
webhook: InteractionWebhook { id: '1125398802182983700' }
}
]
5 August 2023 17:25:57 ERROR [
'Encountered error while handling an interaction handler run method for interaction-handler "ConfirmVerify" at path "F:\\Hosting Bot, LLC\\bot\\dist\\interaction-handlers\\buttons\\verify\\ConfirmVerify.js"',
DiscordAPIError[10008]: Unknown Message
at handleErrors (F:\Hosting Bot, LLC\bot\node_modules\@discordjs\rest\dist\index.js:640:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (F:\Hosting Bot, LLC\bot\node_modules\@discordjs\rest\dist\index.js:1021:23)
at async SequentialHandler.queueRequest (F:\Hosting Bot, LLC\bot\node_modules\@discordjs\rest\dist\index.js:862:14)
at async REST.request (F:\Hosting Bot, LLC\bot\node_modules\@discordjs\rest\dist\index.js:1387:22)
at async MessageManager.edit (F:\Hosting Bot, LLC\bot\node_modules\discord.js\src\managers\MessageManager.js:176:15)
at async ConfirmVerifyInteractionHandler.run (F:\Hosting Bot, LLC\bot\dist\interaction-handlers\buttons\verify\ConfirmVerify.js:46:9)
at async Object.fromAsync (F:\Hosting Bot, LLC\bot\node_modules\@sapphire\result\dist\index.js:613:22)
at async Promise.allSettled (index 0)
at async InteractionHandlerStore.run (F:\Hosting Bot, LLC\bot\node_modules\@sapphire\framework\dist\lib\structures\InteractionHandlerStore.js:48:21) {
requestBody: { files: [], json: [Object] },
rawError: { message: 'Unknown Message', code: 10008 },
code: 10008,
status: 404,
method: 'PATCH',
url: 'https://discord.com/api/v10/channels/1125397046002716855/messages/1137421014578516069'
}
]
from the logger ^ my code snippet relevant to the log
this.container.logger.debug(interaction);

// Send a success message
await interaction.message.edit({
embeds: [embed],
components: [],
});
this.container.logger.debug(interaction);

// Send a success message
await interaction.message.edit({
embeds: [embed],
components: [],
});
but as you can see in the log, the message clearly exists, but when trying to edit it, it's an unknown message thonk
Ben
Ben11mo ago
Thats weird. Is it an ephemeral message? I think there's some weirdness with editing those
b1nzee
b1nzee11mo ago
So the embed is originally created in the ChatInputCommandInteraction with the buttons then the code above is the ButtonHandler / ButtonInteraction its ephemeral yeah
Ben
Ben11mo ago
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.
b1nzee
b1nzee11mo ago
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
Ben
Ben11mo ago
Oh maybe try setting ephemeral to true when you edit the message
b1nzee
b1nzee11mo ago
It's not a property of MessageEditOptions
Ben
Ben11mo ago
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.
b1nzee
b1nzee11mo ago
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 kekw Thanks again for the help