I've troubleshot these bot tons and now I've reached the problem where the code runs, the discord bot comes online in the discord server and I get the "bot is ready message", but when the message is supposed to show the message content after a message is sent in a discord channel (Example: "someone says "hello" my terminal should say "Received Message: Hello")
but it doesn't.
it only says "received message:" and nothing after it no matter what.
I have discord.js v.12 downloaded and node.js downloaded, and the bot runs, but doesn't work. Did I do something wrong in my code?:
const { Client, Intents } = require('discord.js'); const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const TOKEN = 'I'm not gonna show you my bot token silly'; // Replace with your bot's token const PREFIX = '!'; // You can change this to your preferred command prefix
client.once('ready', () => {
console.log(Bot is ready!
);
});
client.on('message', (message) => { // Changed 'messageCreate' to 'message'
console.log(Received message: ${message.content}
);
// Check if the message is from a bot or doesn't start with the prefix
if (message.author.bot || !message.content.startsWith(PREFIX)) {
return; // Ignore the message
}
// Extract the command without the prefix
const command = message.content.slice(PREFIX.length);
// Check if the message has a number (you can customize this check)
const words = command.split(' ');
const number = words.find((word) => !isNaN(word));
// If a number is found, increment it and send the updated number
if (number !== undefined) {
const parsedNumber = parseFloat(number);
if (!isNaN(parsedNumber)) {
const updatedNumber = parsedNumber + 1;
message.channel.send(`Updated number: ${updatedNumber}`);
}
}
});
client.login(TOKEN);