Issues with reading direct messages

Hi, I'm actually developping my bot with discordJS. I'm trying to make an easy function for testing something : - the user sends a command ( test ) - the bot asks the user ( in for example bots channels ) to send 1 or 2 in DMS. - Depending on the answer ( 1,2) it will send a message in the channel (bots) - if it's another thing, it will DM directely the user ( asking to change its choice ) The problem is that the bot can reads the message : "Message Sent by arimak1924 in 1 ( Where 1 is the msg.channel.type ). But the bot doesn't use my DM as it should. I'll send some parts of my code that could be usefull if anyone knows how to do.
7 Replies
d.js toolkit
d.js toolkit•9mo 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
ArimaK
ArimaK•9mo ago
discord JS 14.14.1 - Node 21.3.0 My test function :
export async function handleTest3Command(message) {
const originChannel = message.channel;
message.channel.send("Send 1 or 2 in DM.");

const messageListener = (msg) => {
if (msg.author.bot) return;
console.log(`Message sent by ${msg.author.tag} in ${msg.channel.type}`);

if (msg.channel.type === '1' && msg.author.id === message.author.id) {
if (msg.content === '1') {
originChannel.send("Answer is 1 ");
message.client.removeListener('messageCreate', messageListener);
} else if (msg.content === '2') {
originChannel.send("Answer is 2");
message.client.removeListener('messageCreate', messageListener);
} else {
msg.reply("Please send '1' or '2'.");
}
}
};

message.client.on('messageCreate', messageListener);
}
export async function handleTest3Command(message) {
const originChannel = message.channel;
message.channel.send("Send 1 or 2 in DM.");

const messageListener = (msg) => {
if (msg.author.bot) return;
console.log(`Message sent by ${msg.author.tag} in ${msg.channel.type}`);

if (msg.channel.type === '1' && msg.author.id === message.author.id) {
if (msg.content === '1') {
originChannel.send("Answer is 1 ");
message.client.removeListener('messageCreate', messageListener);
} else if (msg.content === '2') {
originChannel.send("Answer is 2");
message.client.removeListener('messageCreate', messageListener);
} else {
msg.reply("Please send '1' or '2'.");
}
}
};

message.client.on('messageCreate', messageListener);
}
A part of my bot.js ( Intents, DM verification as I tried ) :
const { Client, GatewayIntentBits } = DiscordJS;
const client = new DiscordJS.Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages
],
partials: [
'CHANNEL',
'MESSAGE'
]

----

client.on('messageCreate', async message => {

if (message.channel.type === '1') {

if (message.content === '1' || message.content === '2') {
console.log("salut")
handleTest3Command(message);
} else {
message.reply("Please send '1' or '2'.");
}
return;
}
});
...
}
const { Client, GatewayIntentBits } = DiscordJS;
const client = new DiscordJS.Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages
],
partials: [
'CHANNEL',
'MESSAGE'
]

----

client.on('messageCreate', async message => {

if (message.channel.type === '1') {

if (message.content === '1' || message.content === '2') {
console.log("salut")
handleTest3Command(message);
} else {
message.reply("Please send '1' or '2'.");
}
return;
}
});
...
}
Technically when I send a DM to the bot, it can read it but it stops here. I already tried with message.channel.type === 1 and DM but it's still stuck
treble/luna
treble/luna•9mo ago
Those partials are incorrect
d.js docs
d.js docs•9mo ago
interface Partials The enumeration for partials. ```js (more...)
treble/luna
treble/luna•9mo ago
same for channel type Its a number, and use the enum
d.js docs
d.js docs•9mo ago
dtypes v10: ChannelType read more
ArimaK
ArimaK•9mo ago
Alright thanks I'll try to fix it Work works I thank you PepeSalute
Want results from more Discord servers?
Add your server