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
d.js toolkit
d.js toolkit2y ago
• 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.
ayhamidk
ayhamidkOP2y ago
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)
outsharded
outsharded2y ago
Do you have the message content intent at https://Discord.com/developer
ayhamidk
ayhamidkOP2y ago
?
d.js docs
d.js docs2y ago
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 Intents
sexy dark chocolate
You're supposed to be getting an error as soon as a message is received, does the bot go online?
ayhamidk
ayhamidkOP2y ago
Already done Yes
sexy dark chocolate
You are missing the message content intent in your code too In the client constructor
ayhamidk
ayhamidkOP2y ago
How to add it please?
sexy dark chocolate
Same way you added the GUILD_MESSAGES intent but with MESSAGE_CONTENT Intents.FLAGS.MESSAGE_CONTENT
ayhamidk
ayhamidkOP2y ago
Okey Does not work :/
sexy dark chocolate
Show me It's .split(" ") btw not .slice(" "), if you're talking about your command not working I hus wanna know if it logs
ayhamidk
ayhamidkOP2y ago
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");
sexy dark chocolate
Don't remove the GUILD_MESSAGES intent Keep both of them there
ayhamidk
ayhamidkOP2y ago
Ok
d.js docs
d.js docs2y ago
Codeblocks: ```js const Discord = require("discord.js"); // further code ``` becomes
const Discord = require("discord.js");
// further code
const Discord = require("discord.js");
// further code
Inline Code: `console.log('inline!');` becomes console.log('inline!');
sexy dark chocolate
You can also use this btw
ayhamidk
ayhamidkOP2y ago
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 ?
sexy dark chocolate
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]
ayhamidk
ayhamidkOP2y ago
👌 ?
sexy dark chocolate
This For codeblocks
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");
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");
Alot more sexy ain't it?
ayhamidk
ayhamidkOP2y ago
Okey
ayhamidk
ayhamidkOP2y ago
ayhamidk
ayhamidkOP2y ago
Yeah
sexy dark chocolate
Show me what you did
ayhamidk
ayhamidkOP2y ago
Ok Wait pls
sexy dark chocolate
Also this wasn't for you to copy paste btw I was jus tryna Show the codeblock
ayhamidk
ayhamidkOP2y ago
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
sexy dark chocolate
This is wut u were supposed to do
ayhamidk
ayhamidkOP2y ago
Yes ik
sexy dark chocolate
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: ..."?
ayhamidk
ayhamidkOP2y ago
But my code is correct, right? It works for other developers 😅 No.
sexy dark chocolate
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?
ayhamidk
ayhamidkOP2y ago
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
sexy dark chocolate
Lol it's gonna take a while for discord to show that your bot went offline, meaning your bot goes offline almost instantly
ayhamidk
ayhamidkOP2y ago
Oh :/
sexy dark chocolate
Yeahh, replit isn't for hosting
ayhamidk
ayhamidkOP2y ago
That's clear lol And so if I use a host it should work?
sexy dark chocolate
Yes, your code in the listener might not but it'll recieve messages
ayhamidk
ayhamidkOP2y ago
👌
Want results from more Discord servers?
Add your server