Skip to content

bug: editing a message without a cached channel throws a cryptic error #6578

@DanLop618

Description

@DanLop618

Issue description

../node_modules/discord.js/src/structures/Message.js:627
return this.channel.messages.edit(this, options);

I had a Message.edit() method inside awaitReactions, but when kicking the bot out of the server got this error, i was thinking it happened because when kicking the bot, the channel is not in his cache anymore, so i went to the line 627 in the Message.js structure and added onle line to the code.

I tested it a couple of times both ways, and the second one with the if(!this.channel) return line is working smoothly.
Hope it helps anyone with the same problem!

Codesample

// Original Message.js structure in Discord.js
edit(options) {
  return this.channel.messages.edit(this, options);
}

// Message.js structure edited
edit(options) {
  if(!this.channel) return;
  return this.channel.messages.edit(this, options);
}

discord.js version

13.0.1

Node.js version

16.6.1

Operating system

Windows 10 x64

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

USER, CHANNEL, MESSAGE

Which gateway intents are you subscribing to?

GUILDS, GUILD_MEMBERS, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS

I have tested this issue on a development release

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions