Discord.js: new DMChannel instance being created for every DM

Created on 18 Aug 2019  Â·  6Comments  Â·  Source: discordjs/discord.js

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:

  • discord.js version: latest master
  • Node.js version: v11.14.0
  • Operating system: Windows Vista
  • Priority this issue should have – please be realistic and elaborate if possible: kinda big let's be real
  • Also, message partials are turned on, internal sharding too. This issue never occurred on my test bot, just the main one (it's sharded, maybe that helps), just recently started happening on both.

Possibly related to (or causing) #3324

  • [x] I have also tested the issue on latest master, commit hash: 3fcc862c5fa336bb26c570655245d57e2e532f20
unverified bug

All 6 comments

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.

https://github.com/discordjs/discord.js/blob/3fcc862c5fa336bb26c570655245d57e2e532f20/src/structures/interfaces/TextBasedChannel.js#L127-L132

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shukriadams picture shukriadams  Â·  3Comments

BrandonCookeDev picture BrandonCookeDev  Â·  3Comments

Brawaru picture Brawaru  Â·  3Comments

Lombra picture Lombra  Â·  3Comments

DatMayo picture DatMayo  Â·  3Comments