Can't edit a message in DM sent by bot

- [email protected] and node version v18.10.0 I'm trying to edit a message in DM sent by the bot via a button press. the button event looks like the following (skipped parts not relevant for this question):
async function refreshReminder(interaction: ButtonInteraction<CacheType>) {
interaction.message.edit({ embeds: [reminderEmbed] });
interaction.deferUpdate();
}
async function refreshReminder(interaction: ButtonInteraction<CacheType>) {
interaction.message.edit({ embeds: [reminderEmbed] });
interaction.deferUpdate();
}
This results in the following error:
if (!this.channel) return Promise.reject(new DiscordjsError(ErrorCodes.ChannelNotCached));
^
Error [ChannelNotCached]: Could not find the channel where this message came from in the cache!
at Message.edit (P:\Documents\Programming Projects\Chronos\Chronos\node_modules\discord.js\src\structures\Message.js:691:46)
at refreshReminder (P:\Documents\Programming Projects\Chronos\Chronos\src\index.ts:312:23)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (P:\Documents\Programming Projects\Chronos\Chronos\src\index.ts:146:4) {
code: 'ChannelNotCached'
}
error Command failed with exit code 1.
if (!this.channel) return Promise.reject(new DiscordjsError(ErrorCodes.ChannelNotCached));
^
Error [ChannelNotCached]: Could not find the channel where this message came from in the cache!
at Message.edit (P:\Documents\Programming Projects\Chronos\Chronos\node_modules\discord.js\src\structures\Message.js:691:46)
at refreshReminder (P:\Documents\Programming Projects\Chronos\Chronos\src\index.ts:312:23)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (P:\Documents\Programming Projects\Chronos\Chronos\src\index.ts:146:4) {
code: 'ChannelNotCached'
}
error Command failed with exit code 1.
I also tried a solution i found on stackoverflow from 2021 that looks like the following:
const user = client.users.cache.get(userId);
user?.dmChannel?.messages.fetch(messageId).then(dmMessage => {
dmMessage.edit('edited!');
});
interaction.deferUpdate();
const user = client.users.cache.get(userId);
user?.dmChannel?.messages.fetch(messageId).then(dmMessage => {
dmMessage.edit('edited!');
});
interaction.deferUpdate();
however, this results in the dmChannel property being null and thus not working either
3 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Syjalo
Syjalo2y ago
Did you use update or defer update before editing?
Ben
BenOP2y ago
solved it by adding partials: [Partials.Channel] to the client constructor (
const client = new Client({partials: [Partials.Channel]})
const client = new Client({partials: [Partials.Channel]})
)
Want results from more Discord servers?
Add your server