Channel is not in cache when button interaction is used.

I tried making a button that would delete the message when clicked, but this error showed up: The Error
uncaughtException: Error [ChannelNotCached]: Could not find the channel where this message came from in the cache!
at Message.delete (D:\Gits\dqm\backend-next\node_modules\discord.js\src\structures\Message.js:828:30)
at NewCli.<anonymous> (D:\Gits\dqm\backend-next\src\server\client.ts:33:39)
at NewCli.emit (node:events:514:28)
at NewCli.emit (node:domain:488:12)
at InteractionCreateAction.handle (D:\Gits\dqm\backend-next\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at Object.module.exports [as INTERACTION_CREATE] (D:\Gits\dqm\backend-next\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (D:\Gits\dqm\backend-next\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (D:\Gits\dqm\backend-next\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (D:\Gits\dqm\backend-next\node_modules\@vladfrangu\async_event_emitter\src\index.ts:356:28)
at WebSocketShard.<anonymous> (D:\Gits\dqm\backend-next\node_modules\@discordjs\ws\src\strategies\sharding\SimpleShardingStrategy.ts:32:47)
at WebSocketShard.emit (D:\Gits\dqm\backend-next\node_modules\@vladfrangu\async_event_emitter\src\index.ts:356:28)
at WebSocketShard.onMessage (D:\Gits\dqm\backend-next\node_modules\@discordjs\ws\src\ws\WebSocketShard.ts:630:10)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ChannelNotCached'
}
uncaughtException: Error [ChannelNotCached]: Could not find the channel where this message came from in the cache!
at Message.delete (D:\Gits\dqm\backend-next\node_modules\discord.js\src\structures\Message.js:828:30)
at NewCli.<anonymous> (D:\Gits\dqm\backend-next\src\server\client.ts:33:39)
at NewCli.emit (node:events:514:28)
at NewCli.emit (node:domain:488:12)
at InteractionCreateAction.handle (D:\Gits\dqm\backend-next\node_modules\discord.js\src\client\actions\InteractionCreate.js:97:12)
at Object.module.exports [as INTERACTION_CREATE] (D:\Gits\dqm\backend-next\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (D:\Gits\dqm\backend-next\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (D:\Gits\dqm\backend-next\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (D:\Gits\dqm\backend-next\node_modules\@vladfrangu\async_event_emitter\src\index.ts:356:28)
at WebSocketShard.<anonymous> (D:\Gits\dqm\backend-next\node_modules\@discordjs\ws\src\strategies\sharding\SimpleShardingStrategy.ts:32:47)
at WebSocketShard.emit (D:\Gits\dqm\backend-next\node_modules\@vladfrangu\async_event_emitter\src\index.ts:356:28)
at WebSocketShard.onMessage (D:\Gits\dqm\backend-next\node_modules\@discordjs\ws\src\ws\WebSocketShard.ts:630:10)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ChannelNotCached'
}
The Code
// interaction code

if (inter.customId == "selfdestruct") {
await inter.message.delete()
}

// message code

const cancel = new ButtonBuilder()
.setCustomId(`selfdestruct`)
.setLabel('Cancel')
.setStyle(ButtonStyle.Secondary)

const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents(confirm, cancel)


inter.reply({ embeds: [embed], components: [row] })
// interaction code

if (inter.customId == "selfdestruct") {
await inter.message.delete()
}

// message code

const cancel = new ButtonBuilder()
.setCustomId(`selfdestruct`)
.setLabel('Cancel')
.setStyle(ButtonStyle.Secondary)

const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents(confirm, cancel)


inter.reply({ embeds: [embed], components: [row] })
The Version
node 20.8.0
d.js 14.14.1
node 20.8.0
d.js 14.14.1
6 Replies
d.js toolkit
d.js toolkit12mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Danial
Danial12mo ago
Do you have the Guilds intent?
doqe
doqeOP12mo ago
nope
Danial
Danial12mo ago
There's your issue then
doqe
doqeOP12mo ago
added it and it works, thx <:missi_thumbs:1117909278066475128>
Danial
Danial12mo ago
Of course
Want results from more Discord servers?
Add your server