Please describe the problem you are having in as much detail as possible:
Each DM has channel property referring to a different DMChannel instance, despite being in the same channel with the same channel ID. New DMChannel instances seem to be created for every DM.
Include a reproducible code sample here, if possible:
const { Structures } = require('discord.js');
module.exports = Structures.extend('DMChannel', (DMChannel) => {
class CoolerDMChannel extends DMChannel {
constructor(...args) {
super(...args);
console.log('init dm', this.id);
}
}
return CoolerDMChannel;
});
// every message now gives:
// init dm 522873632003981318
// init dm 522873632003981318
Further details:
Possibly related to (or causing) #3324
This is not a bug. There is a better way to handle it instead of creating a new DM channel every time but it's not a bug. https://github.com/discordjs/discord.js/blob/3fcc862c5fa336bb26c570655245d57e2e532f20/src/structures/interfaces/TextBasedChannel.js#L127-L132
Is this behavior documented?
Is this behavior documented?
No
This could explain why DM channels are not "cached" (which causes message.channel.messages.size to always be 1 in DMs), and in my opinion this IS a bug, contrary to what @Fyk0 says
This is not a bug. There is a better way to handle it instead of creating a new DM channel every time but it's not a bug.
I don't think this code is relevant to the issue, since createDM() will return the ChannelStore-cached DMChannel instance if there is one (await msg.author.createDM() === await msg.author.createDM()).
The issue is that the DMs I receive in my event handlers all spawn a new DMChannel instance, instead of returning the cached one.
Oh I think we just misunderstood in general - the issue regards received DMs, not creating DMs.