interaction.channel is null in DM

it works for servers, but not in direct message as 'user app'. I already use as suggestions of others similar questions, but I am not sure what I am missing:
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent
],
partials: ['MESSAGE', 'CHANNEL', 'REACTION']

});
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent
],
partials: ['MESSAGE', 'CHANNEL', 'REACTION']

});
command is as follow:
const { ContextMenuCommandBuilder, ApplicationCommandType, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');

module.exports = {
data: new ContextMenuCommandBuilder()
.setName('Translate It v2')
.setType(ApplicationCommandType.Message),

async execute(interaction) {
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('translate-en')
.setLabel('Translate to English')
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId('translate-es')
.setLabel('Translate to Spanish')
.setStyle(ButtonStyle.Primary)
);

await interaction.reply({ content: 'Choose the language to translate:', components: [row], ephemeral: true });
try {
const filter = i => i.user.id === interaction.user.id;
const buttonInteraction = await interaction.channel.awaitMessageComponent({ filter, time: 15000 });
...
const { ContextMenuCommandBuilder, ApplicationCommandType, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');

module.exports = {
data: new ContextMenuCommandBuilder()
.setName('Translate It v2')
.setType(ApplicationCommandType.Message),

async execute(interaction) {
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('translate-en')
.setLabel('Translate to English')
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId('translate-es')
.setLabel('Translate to Spanish')
.setStyle(ButtonStyle.Primary)
);

await interaction.reply({ content: 'Choose the language to translate:', components: [row], ephemeral: true });
try {
const filter = i => i.user.id === interaction.user.id;
const buttonInteraction = await interaction.channel.awaitMessageComponent({ filter, time: 15000 });
...
3 Replies
d.js toolkit
d.js toolkit7mo 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! - Marked as resolved by OP
-Carlos👑
-Carlos👑7mo ago
Use the Partial enum for partials, since partials are numbers
Xaphy
XaphyOP7mo ago
It worked, thanks.
const { Client, Collection, Events, GatewayIntentBits , Partials } = require('discord.js');

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent // Necesario para leer el contenido del mensaje en DMs
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction] // Include MESSAGE and REACTION if needed

});
const { Client, Collection, Events, GatewayIntentBits , Partials } = require('discord.js');

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent // Necesario para leer el contenido del mensaje en DMs
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction] // Include MESSAGE and REACTION if needed

});
Want results from more Discord servers?
Add your server