ArimaK
ArimaK
DIAdiscord.js - Imagine a boo! 👻
Created by ArimaK on 1/31/2024 in #djs-questions
Issues with reading direct messages
It works I thank you PepeSalute
12 replies
DIAdiscord.js - Imagine a boo! 👻
Created by ArimaK on 1/31/2024 in #djs-questions
Issues with reading direct messages
Alright thanks I'll try to fix it Work
12 replies
DIAdiscord.js - Imagine a boo! 👻
Created by ArimaK on 1/31/2024 in #djs-questions
Issues with reading direct messages
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
12 replies
DIAdiscord.js - Imagine a boo! 👻
Created by ArimaK on 1/31/2024 in #djs-questions
Issues with reading direct messages
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;
}
});
...
}
12 replies
DIAdiscord.js - Imagine a boo! 👻
Created by ArimaK on 1/31/2024 in #djs-questions
Issues with reading direct messages
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);
}
12 replies