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

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'] });
let member = await client.users.fetch(memberId)
let message = await member.dmChannel.awaitMessages({ filter, max: 1, time: timeOutTime, errors: ['time'] });
14 Replies
d.js toolkit
d.js toolkit17mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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!
Kinect3000
Kinect300017mo ago
Fetching a user doesn’t include the dm channel You either have to open one or send a dm, if ur alr doing that
d.js docs
d.js docs17mo ago
method User#createDM() Creates a DM channel between the client and the user.
RobbyV
RobbyVOP17mo ago
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
Kinect3000
Kinect300017mo ago
Await the user.send
RobbyV
RobbyVOP17mo ago
I do that
let message = await member.send({ embeds: [promptEmbed] })
let message = await member.send({ embeds: [promptEmbed] })
Kinect3000
Kinect300017mo ago
Ur sending the message before calling awaitMessages?
RobbyV
RobbyVOP17mo ago
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
Kinect3000
Kinect300017mo ago
Can you show the whole function?
RobbyV
RobbyVOP17mo ago
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
}
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
}
Kinect3000
Kinect300017mo ago
Oh, ur sharding
RobbyV
RobbyVOP17mo ago
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. Sorry I didn't see your original message but yeah that should do the same thing
GitHub
GitHub17mo ago
<:pr_open:852715356622553088> #9774 in discordjs/discord.js by Jiralite opened <t:1691976884:R> (review required) fix(Action): Do not add the client user as a recipient
RobbyV
RobbyVOP17mo ago
Awesome, thanks. Oh, I didn’t know I could do that, thanks so much for the tip!
Want results from more Discord servers?
Add your server