How do I get the bot to respond to DM messages that are written to it from the user?

I still can't find an example where there is an event that would trigger whenever a user writes a message to a bot in the DM
16 Replies
d.js toolkit
d.js toolkit10mo 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!
Dmitry Batkovich
Dmitry Batkovich10mo ago
for a chat on the server, it is clear that there is a message Create, but it is not called if the user writes a message to the DM The bot has shared all the rights in the console and also here is its config:
const client = new Client
({
intents:
[
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
IntentsBitField.Flags.GuildMessageTyping,
IntentsBitField.Flags.DirectMessages,
IntentsBitField.Flags.DirectMessageReactions,
IntentsBitField.Flags.DirectMessageTyping,
],
partials: ['MESSAGE', 'CHANNEL', 'REACTION']
});
const client = new Client
({
intents:
[
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
IntentsBitField.Flags.GuildMessageTyping,
IntentsBitField.Flags.DirectMessages,
IntentsBitField.Flags.DirectMessageReactions,
IntentsBitField.Flags.DirectMessageTyping,
],
partials: ['MESSAGE', 'CHANNEL', 'REACTION']
});
by the way, he does not react to the message at all, as I understand it, it was cut out of version 14?
client.on('message',(message) =>
{
console.log("message!");
});
client.on('message',(message) =>
{
console.log("message!");
});
this does not work either on the server in the chat or in the DM chat with the bot
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Dmitry Batkovich
Dmitry Batkovich10mo ago
client.on('messageCreate', async (message) =>
{
console.log("message!");
});
client.on('messageCreate', async (message) =>
{
console.log("message!");
});
this only works on the server in chats and where to get them?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Dmitry Batkovich
Dmitry Batkovich10mo ago
so what's next? will the message Create or message event work by itself?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Dmitry Batkovich
Dmitry Batkovich10mo ago
ok I replaced what's next?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Dmitry Batkovich
Dmitry Batkovich10mo ago
message event don't work
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Dmitry Batkovich
Dmitry Batkovich10mo ago
should I replace it with message Create? ok don't working: console log:
PS D:\KJPiTechnologes\discordbots\research> node src/index.js
Logged in as Research#4345!
PS D:\KJPiTechnologes\discordbots\research> node src/index.js
Logged in as Research#4345!
PS D:\KJPiTechnologes\discordbots\research> node src/index.js
Logged in as Research#4345!
PS D:\KJPiTechnologes\discordbots\research> node src/index.js
Logged in as Research#4345!
PS D:\KJPiTechnologes\discordbots\research> node src/index.js
Logged in as Research#4345!
PS D:\KJPiTechnologes\discordbots\research> node src/index.js
Logged in as Research#4345!
PS D:\KJPiTechnologes\discordbots\research> node src/index.js
Logged in as Research#4345!
PS D:\KJPiTechnologes\discordbots\research> node src/index.js
Logged in as Research#4345!
PS D:\KJPiTechnologes\discordbots\research> node src/index.js
Logged in as Research#4345!
PS D:\KJPiTechnologes\discordbots\research> node src/index.js
Logged in as Research#4345!
PS D:\KJPiTechnologes\discordbots\research> node src/index.js
Logged in as Research#4345!
PS D:\KJPiTechnologes\discordbots\research> node src/index.js
Logged in as Research#4345!
const {Client, IntentsBitField} = require('discord.js');
const { spawn } = require('child_process');
const exePath = 'src/server/GPTServer.exe';
const client = new Client
({
intents:
[
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
IntentsBitField.Flags.GuildMessageTyping,
IntentsBitField.Flags.DirectMessages,
IntentsBitField.Flags.DirectMessageReactions,
IntentsBitField.Flags.DirectMessageTyping,
]
});

const { Partials } = require('discord.js');

const botToken = 'token_bot';

client.on('ready', () =>
{
console.log(`Logged in as ${client.user.tag}!`);
});

client.on('messageCreate',(message) =>
{
console.log("message!");
});

client.login(botToken);
const {Client, IntentsBitField} = require('discord.js');
const { spawn } = require('child_process');
const exePath = 'src/server/GPTServer.exe';
const client = new Client
({
intents:
[
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
IntentsBitField.Flags.GuildMessageTyping,
IntentsBitField.Flags.DirectMessages,
IntentsBitField.Flags.DirectMessageReactions,
IntentsBitField.Flags.DirectMessageTyping,
]
});

const { Partials } = require('discord.js');

const botToken = 'token_bot';

client.on('ready', () =>
{
console.log(`Logged in as ${client.user.tag}!`);
});

client.on('messageCreate',(message) =>
{
console.log("message!");
});

client.login(botToken);
when sending a message to the DM, message does not appear in the console! the token of the bot in the studio is here, I removed it so that I didn't have to restart it later
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Dmitry Batkovich
Dmitry Batkovich10mo ago
and how to do it, what to write there? simply
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
?
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Dmitry Batkovich
Dmitry Batkovich10mo ago
const {Client, IntentsBitField} = require('discord.js');
const { spawn } = require('child_process');
const exePath = 'src/server/GPTServer.exe';
const client = new Client
({
intents:
[
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
IntentsBitField.Flags.GuildMessageTyping,
IntentsBitField.Flags.DirectMessages,
IntentsBitField.Flags.DirectMessageReactions,
IntentsBitField.Flags.DirectMessageTyping,
],
partials:
[
Partials.Message,
Partials.Channel,
Partials.Reaction
]
});
const {Client, IntentsBitField} = require('discord.js');
const { spawn } = require('child_process');
const exePath = 'src/server/GPTServer.exe';
const client = new Client
({
intents:
[
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
IntentsBitField.Flags.GuildMessageTyping,
IntentsBitField.Flags.DirectMessages,
IntentsBitField.Flags.DirectMessageReactions,
IntentsBitField.Flags.DirectMessageTyping,
],
partials:
[
Partials.Message,
Partials.Channel,
Partials.Reaction
]
});
ReferenceError: Partials is not defined
at Object.<anonymous> (D:\KJPiTechnologes\discordbots\research\src\index.js:19:5)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47

Node.js v18.17.0
ReferenceError: Partials is not defined
at Object.<anonymous> (D:\KJPiTechnologes\discordbots\research\src\index.js:19:5)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47

Node.js v18.17.0
is there any other library needed here? or should I add something to the constant?
const {Client, IntentsBitField} = require('discord.js');
const {Client, IntentsBitField} = require('discord.js');
before that when it was like this:
partials: ['MESSAGE', 'CHANNEL', 'REACTION']
partials: ['MESSAGE', 'CHANNEL', 'REACTION']
there was no mistake but it didn't lead to anything working BIG THANKS!