When running your code on discord.js 14.19.2 and node v22.14.0, I receive the following output in the terminal:
carolina@Carolinas-MacBook-Air test % node index.js
Beep! Beep!🤖Bot Pending!
Beep! Beep!🤖Bot Running!
The bot is also shown as online in the Discord server I have invited it to. On my end, it does work. (Note: obviously at this stage, you can't do anything with the Discord bot as you haven't implemented any commands, but it should be displaying as online as it does for me).
Given this, I would ask that you comment providing further information about the version of node and discord.js that you are using, and to confirm that you have added the Discord bot to your server? Without this information, we can't provide further help, given you did state above that it does not work.
Some changes I would recommend to improve your code's readability in the meantime:
package.json
Add the following:
"type": "module",
index.js
// Imports at the top, switch to ES6 imports if possible instead of CommonJS
import { Client, Events, GatewayIntentBits } from "discord.js";
// Switch from string intents to the IntentsBitField class for better type safety
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages
]
});
console.log("Beep! Beep!🤖Bot Pending!");
// Improve clarity by moving the console.log inside of the event listener
// Switch from string events to the Events enum for better type safety
client.on(Events.ClientReady, () => {
console.log("Beep! Beep!🤖Bot Running!");
});
// Ensure login() is always the last line in the file, and token is stored in a separate file.
client.login("token");
Other really useful resources include: