-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Changes to getChannel method in 14.26.2 leading to Bots not reacting to DMs anymore #11486
Description
Which package is this bug report for?
discord.js
Issue description
When updating to 14.26.2, my bot doesn't seem to notice DM messages anymore. I could pin down the problem to this change. When I dumped data after writing, I saw that type was never part of the event and thus, always undefined. As the conditional doesn't include a fallback anymore, no DMs could be reacted to.
Context
Implementation sample on my side, working with 14.26.1:
this.client.on('messageCreate', async (message) => {
const messageContent = message?.content;
const isDM = message?.channel?.type == ChannelType.DM;
if (
message?.author?.bot ||
messageContent?.includes('@here') ||
messageContent?.includes('@everyone') ||
// Answer to replies or direct mentions - both are mentions, unless it's a DM
(!isDM && !message?.mentions?.has(this.client?.user?.id ?? ''))
) {
return;
}
[working code...]
I then put this into Action.js and sent a DM to my bot.
getChannel(data) {
const payloadData = {};
const id = data.channel_id ?? data.id;
console.log('Data received for channel:', data);
if ('recipients' in data) {
// Try to resolve the recipient, but do not add if already existing in recipients.
const recipient = data.author ?? data.user ?? { id: data.user_id };
if (!data.recipients.some(existingRecipient => recipient.id === existingRecipient.id)) {
payloadData.recipients = [...data.recipients, recipient];
}
# There is no fallback anymore, which is a problem.
} else if (data.type === ChannelType.DM || data.type === ChannelType.GroupDM) {
// Try to resolve the recipient.
const recipient = data.author ?? data.user ?? { id: data.user_id };
payloadData.recipients = [recipient];
}
[working code...]
This is the result:
Data received for channel: {
id: '<omitted>',
author: {
username: '<omitted>',
public_flags: 0,
primary_guild: {
tag: '<omitted>',
identity_guild_id: '<omitted>',
identity_enabled: true,
badge: '<omitted>'
},
id: '<omitted>',
global_name: '<omitted>',
display_name_styles: <omitted>,
discriminator: '0',
collectibles: { nameplate: [Object] },
clan: {
tag: '<omitted>',
identity_guild_id: '<omitted>',
identity_enabled: true,
badge: '<omitted>'
},
avatar_decoration_data: {
sku_id: '<omitted>',
expires_at: null,
asset: '<omitted>'
},
avatar: '<omitted>'
}
}
As you can see, there is only data.id and data.author, data.type is not available, thus the event never gets further as the conditional just stops without fallback.
Code sample
Versions
- discord.js 14.25.2
- Node.js 24
Issue priority
Medium (should be fixed soon)
Which partials do you have configured?
Channel, Message, GuildMember
Which gateway intents are you subscribing to?
Guilds, GuildMembers, GuildMessages, DirectMessages, MessageContent, GuildVoiceStates
I have tested this issue on a development release
No response