how to add a listener so if someone sent message in the server, the bot does action ?

i want to make console.log that there is a user sent message .. how to do that ? it's like a listener ig .. i used this but it didn't work :
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});

client.on('message', (message) => {
// Code to handle incoming messages
console.log(`Received message: ${message.content}`);
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});

client.on('message', (message) => {
// Code to handle incoming messages
console.log(`Received message: ${message.content}`);
});
19 Replies
d.js toolkit
d.js toolkit12mo 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 staff
treble/luna
treble/luna12mo ago
its messageCreate you need the Guilds, GuildMessages, and MessageContent intent
Maklord
MaklordOP12mo ago
?
treble/luna
treble/luna12mo ago
yes
Maklord
MaklordOP12mo ago
it still doesn't work
treble/luna
treble/luna12mo ago
and did you add the intents i told you
Maklord
MaklordOP12mo ago
when i send message such as " test " .. there is no action i was going to ask you where are these things in the docs
d.js docs
d.js docs12mo ago
guide Popular Topics: Gateway Intents read more
Maklord
MaklordOP12mo ago
sorry iam a beginner :/ well
treble/luna
treble/luna12mo ago
you're better of starting with v14 it has all the new features
Maklord
MaklordOP12mo ago
@polarwolvinny ❄ 🌈 is that correct ? sure
treble/luna
treble/luna12mo ago
why do you have 2 clients you only need 1
Maklord
MaklordOP12mo ago
ok there are two clients bec i use one for other things, and one for the messages
treble/luna
treble/luna12mo ago
thats not how it works you only need one client you can do everything with one
Maklord
MaklordOP12mo ago
hm ok do you see to use the first client or the second one ? i mean the part of " new Client " and " new Discord.Client "
treble/luna
treble/luna12mo ago
either destructure or dont but not both and not twice
Maklord
MaklordOP12mo ago
ok @polarwolvinny ❄ 🌈 now iam using one client and the messageCreate code is everything fine now or something left ?
treble/luna
treble/luna12mo ago
you dont have the GuildMessages intent
Maklord
MaklordOP12mo ago
oh yeah wait @polarwolvinny ❄ 🌈 it works now thank you very much
Want results from more Discord servers?
Add your server