Discord.js is a comprehensive, performant, and object-oriented JavaScript library designed for interacting with the Discord API. It simplifies bot development by abstracting complex API calls and WebSocket management, providing a rich set of classes and utilities. The current stable version is 14.26.3, and the library maintains a frequent release cadence, often pushing out minor bug fixes and new features to keep pace with Discord's evolving API, as evidenced by the rapid 14.26.x updates. Key differentiators include its extensive documentation, a large and active community, and a modular ecosystem (e.g., `@discordjs/rest`, `@discordjs/builders`, `@discordjs/voice`) that allows developers to integrate specific functionalities as needed. It supports both CommonJS and ES Modules, with modern usage heavily favoring ESM and TypeScript for type safety and modern JavaScript features.
npm install discord.jsVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes a basic Discord bot, logs it in, and makes it respond to 'ping' and 'hello' messages in any channel it has access to. It demonstrates mandatory intents and best practices for token management.
Upgrade your Node.js environment to version 18.x or newer. For v14.26.2, Node.js 22.12.0 or newer is required.
Specify all necessary `GatewayIntentBits` in the `Client` constructor. For privileged intents like `MessageContent`, `GuildMembers`, and `GuildPresences`, enable them in your bot's settings on the Discord Developer Portal.
Update event listeners to use the new `Events` enum properties (e.g., `Events.MessageCreate`, `Events.InteractionCreate`). Refer to the v13 to v14 update guide for a full list of changes.
Ensure Node.js v18+ is used. Adapt any direct interactions with `REST` internals, especially `rest.raw` and `parseResponse`, to handle web-compatible `Response` objects.
Add required `Partials` (e.g., `Partials.Message`, `Partials.Channel`, `Partials.User`) to the `Client` constructor's `partials` array. Also, ensure privileged intents are enabled for related data.
Use ES module `import` syntax for `discord.js` and other dependencies. Ensure your scripts are correctly configured as ES modules or CommonJS modules as appropriate for your project setup.
Provide an array of `GatewayIntentBits` to the `intents` property in the `Client` constructor. Remember to also enable privileged intents in the Discord Developer Portal if needed.
Verify the bot token in your code matches the token from the Discord Developer Portal. Regenerate the token on the portal if unsure, and ensure it's kept private.
Replace `Intents.FLAGS.<INTENT_NAME>` with `GatewayIntentBits.<IntentName>` and ensure `GatewayIntentBits` is imported from `discord.js`.
Change your import statements from `const Discord = require('discord.js');` to `import * as Discord from 'discord.js';` or `import { Client } from 'discord.js';`. Alternatively, ensure your `package.json` does not have `"type": "module"` if you intend to use CommonJS.