#member.dmChannel.awaitMessages() breaking when updating from v14.11 to v14.12

26 messages · Page 1 of 1 (latest)

humble badger
#

I currently have the following code which works perfectly in discord.js v14.11 however when I upgraded to v14.12, I started getting the following error Cannot read properties of null (reading 'awaitMessages'). This can't be an issue with the code since when I downgrade back to v14.11 it starts working perfectly again so I'm not sure what's going on.

let member = await client.users.fetch(memberId)
let message = await member.dmChannel.awaitMessages({ filter, max: 1, time: timeOutTime, errors: ['time'] });
vivid topazBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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!
solar torrent
#

Fetching a user doesn’t include the dm channel

#

You either have to open one or send a dm, if ur alr doing that

jagged rivetBOT
humble badger
#

Why did it work in 14.11 though?

#

As well as every version of 14 prior to the current one

#

Also the bot does DM the user before awaiting the message

solar torrent
#

Await the user.send

humble badger
#

I do that

let message = await member.send({ embeds: [promptEmbed] })
solar torrent
#

Ur sending the message before calling awaitMessages?

humble badger
#

Yeah, it's quite a bit higher in the function though

#

But there is definitely a DM open with the user before it tries to await a message

solar torrent
#

Can you show the whole function?

humble badger
#

It's a little bit of a mess but sure

#
if (!embedData) return Error('Failed to provide embed data.');
        if (this.previousMessage) await this.previousMessage.delete();
        let filter = m => m.author.id == this.interaction.user.id;
        let promptEmbed = new Discord.EmbedBuilder(embedData).setFooter({ text: cancelPromptMessage }).setTimestamp(Date.now());
        if ((promptEmbed.title == '') || !promptEmbed) promptEmbed.setTitle(this.title);
        if (skipable) promptEmbed.setFooter({ text: skipPromptMessage });
        let memberId = this.interaction.user.id
        let newPrompt = (await this.interaction.client.shard.broadcastEval(async (client, { promptEmbed, memberId }) => {
            let member = await client.users.fetch(memberId)
            if (member && client.shard.ids == 0) {
                let message = await member.send({ embeds: [promptEmbed] })
                return [message, message.url]
            }
        }, { context: { promptEmbed, memberId } }).catch(async () => {
            return [false]
        }))[0]
        if (newPrompt == false) {
            this.endPrompt('errorWithReason', "We couldn't send you a DM as they are closed.");
            return
        }
        let ActionRow = new Discord.ActionRowBuilder()
        const movedToDMButton = ActionRow.addComponents(new Discord.ButtonBuilder().setURL(newPrompt[1]).setLabel('Jump to DM').setStyle(Discord.ButtonStyle.Link));
        if (this.interaction.deferred || this.interaction.replied) {
            await this.interaction.editReply({ embeds: [movedToDM], components: [movedToDMButton] })
        } else {
            await this.interaction.reply({ embeds: [movedToDM], components: [movedToDMButton] })
        }
        this.redirectedToDMs = true
        try {
            let message = (await this.interaction.client.shard.broadcastEval(async (client, { memberId, filter, timeOutTime }) => {
                let member = await client.users.fetch(memberId)
                if (client.shard.ids[0] == 0) {
                    let message = await member.dmChannel.awaitMessages({ filter, max: 1, time: timeOutTime, errors: ['time'] });
                    if (message.first() && message.first().attachments.first()) return [message.first(), message.first().attachments.first()]
                    else if (message.first() && !message.first().attachments.first()) return [message.first()]
                }
            }, { context: { memberId, filter, timeOutTime } }))[0]
            if (message[0].content == 'cancel') {
                this.endPrompt('cancel')
                return
            }
            if (message[0].content == 'skip' && skipable) return false;
            if (message[1]) {
                let newData = message[0]
                newData.attachments = message[1]
                return newData;
            }
            return message[0];
        } catch {
            this.endPrompt('time');
            return false
        }```
solar torrent
#

Oh, ur sharding

humble badger
#

Yeah I don't have a choice unfortunately which adds extra complications to everything

#

I have a feeling this is a bug in 14.12.0 and above just because of the fact that it immediately fixes itself when I downgrade to 14.11.0.

nova path
#

If you could get a minimum reproducible code sample, that would be great

nova path
#

Managed to get one

client.on(Events.ClientReady, async () => {
    const user = await client.users.fetch("user_id");
    const message = await user.send("Hi");
    console.log(message.channel);
});
humble badger
#

Sorry I didn't see your original message but yeah that should do the same thing

vestal oarBOT
nova path
#

You can patch that fix in if you want

humble badger
#

Awesome, thanks.

robust vortex