The bot does not answer
Hello 👋
I have a problem with my discord.js v13 code, the code looks ok, no errors in the console, the bot is connected but it does not answer
40 Replies
• What's your exact discord.js
npm list discord.js
and node node -v
version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.const { Client, Intents, MessageEmbed } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILD_MESSAGES] });
const prefix = 'S!';
client.on('ready', () => {
console.log('Bot opérationnel');
});
client.on('messageCreate', async message => {
const args = message.content.slice(" ")
console.log('Received message:', message.content);
if (!message.content.startsWith(prefix)) return;
if(args[0] ===
${prefix}open) {
const embed = new MessageEmbed()
.setColor('#75E6DA')
.setTitle('Test')
.setDescription('Test')
.setTimestamp();
await message.channel.send({ embeds: [embed] })
.then(() => console.log('Message sent:', embed))
.catch(console.error);
}
});
client.login("My token");
(Using replit)Do you have the message content intent at https://Discord.com/developer
?
Error [DisallowedIntents]: Privileged intent provided is not enabled or whitelisted.
If you are using the GuildMembers
, GuildPresences
, or MessageContent
intents, you need to enable them in the developer portal:
- Developer Portal > Your app > Bot > Privileged Gateway IntentsYou're supposed to be getting an error as soon as a message is received, does the bot go online?
Already done
Yes
You are missing the message content intent in your code too
In the client constructor
How to add it please?
Same way you added the GUILD_MESSAGES intent but with MESSAGE_CONTENT
Intents.FLAGS.MESSAGE_CONTENT
Okey
Does not work :/
Show me
It's .split(" ") btw not .slice(" "), if you're talking about your command not working
I hus wanna know if it logs
const { Client, Intents, MessageEmbed } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.MESSAGE_CONTENT] });
const prefix = 'S!';
client.on('ready', () => {
console.log('Bot opérationnel');
});
client.on('messageCreate', async message => {
const args = message.content.slice(" ")
console.log('Received message:', message.content);
if (!message.content.startsWith(prefix)) return;
if(args[0] ===
${prefix}open) {
const embed = new MessageEmbed()
.setColor('#75E6DA')
.setTitle('Test')
.setDescription('Test')
.setTimestamp();
await message.channel.send({ embeds: [embed] })
.then(() => console.log('Message sent:', embed))
.catch(console.error);
}
});
client.login("My token");
Don't remove the GUILD_MESSAGES intent
Keep both of them there
Ok
Codeblocks:
```js
const Discord = require("discord.js");
// further code
```
becomes
Inline Code:
`console.log('inline!');` becomes
console.log('inline!');
You can also use this btw
const { Client, Intents, MessageEmbed } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.MESSAGE_CONTENT.GUILD_MESSAGES] });
const prefix = 'S!';
client.on('ready', () => {
console.log('Bot opérationnel');
});
client.on('messageCreate', async message => {
const args = message.content.slice(" ")
console.log('Received message:', message.content);
if (!message.content.startsWith(prefix)) return;
if(args[0] ===
${prefix}open) {
const embed = new MessageEmbed()
.setColor('#75E6DA')
.setTitle('Test')
.setDescription('Test')
.setTimestamp();
await message.channel.send({ embeds: [embed] })
.then(() => console.log('Message sent:', embed))
.catch(console.error);
}
});
client.login("My token");
Like that ?I still see a bunch of inline code but we'd ignore it for now, it's not important to me
And no that's not how you add the intents
It's an array of intents,
[Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.MESSAGE_CONTENT]
👌
?
This
For codeblocks
Alot more sexy ain't it?
Okey
Yeah
Show me what you did
Ok
Wait pls
Also this wasn't for you to copy paste btw I was jus tryna Show the codeblock
It's good infact I didn't add the intents well but it's done. But still the same problem the bot does not answer while connected. I think I'll watch some tutorials because the one I watched is in visual studio code
This is wut u were supposed to do
Yes ik
Where you code it shouldn't matter in terms of receiving messages and tutorials most of the time won't help, you can look at the v13 guide though
Also, it doesn't log "Recieved message: ..."?
But my code is correct, right? It works for other developers
😅
No.
Yes your code is correct in terms of receiving messages, is your bot online when you're sending the message? Are you in a channel that the bot has access to?
Yes, the bot is connected and has access to the channel. On the other hand, it only connects for a few seconds then it turns off, but I execute the command when it is connected
Lol it's gonna take a while for discord to show that your bot went offline, meaning your bot goes offline almost instantly
Oh :/
Yeahh, replit isn't for hosting
That's clear lol
And so if I use a host it should work?
Yes, your code in the listener might not but it'll recieve messages
👌