Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsJul 15, 2026·3 min de lecture

Discord.js — Powerful JavaScript Library for Discord Bot Development

A robust Node.js module for interacting with the Discord API, enabling developers to build bots with slash commands, voice support, and real-time event handling.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Discord.js Overview
Commande d'installation directe
npx -y tokrepo@latest install f0670c73-808d-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

Discord.js is a Node.js module that provides a straightforward interface for interacting with the Discord API. It supports every Discord feature including slash commands, message components, voice connections, and gateway events, making it the go-to library for JavaScript-based Discord bots.

What Discord.js Does

  • Wraps the full Discord REST API and WebSocket gateway in an idiomatic JavaScript interface
  • Handles rate limiting, caching, and reconnection logic automatically
  • Supports slash commands, context menus, modals, buttons, and select menus
  • Provides voice support through the companion @discordjs/voice package
  • Offers built-in sharding for bots serving thousands of guilds

Architecture Overview

Discord.js connects to the Discord Gateway via WebSocket to receive real-time events (messages, reactions, member updates) and uses the REST API for actions like sending messages or managing roles. The library uses an internal cache layer that stores guilds, channels, and users in memory for fast lookups. For large bots, a ShardingManager spawns multiple processes, each handling a subset of guilds.

Self-Hosting & Configuration

  • Requires Node.js 18 or newer
  • Install via npm or yarn: npm install discord.js
  • Create a bot application at discord.com/developers and obtain a token
  • Set gateway intents in both the developer portal and your client constructor
  • Deploy anywhere Node.js runs: VPS, Docker container, or serverless with keep-alive

Key Features

  • Full coverage of Discord API v10 including threads, forums, and auto-moderation
  • Strongly typed with built-in TypeScript declarations
  • Collectors and event-based patterns for interactive bot flows
  • Companion packages: @discordjs/builders, @discordjs/rest, @discordjs/voice
  • Active maintenance with frequent releases tracking Discord API changes

Comparison with Similar Tools

  • discord.py — Python equivalent; Discord.js is the JavaScript counterpart with a larger plugin ecosystem
  • Eris — Lighter Node.js alternative with less abstraction but fewer convenience features
  • JDA — Java Discord library; Discord.js is easier to prototype with but JDA suits JVM-based stacks
  • Serenity — Rust Discord framework; higher performance but steeper learning curve

FAQ

Q: What are gateway intents and why do I need them? A: Intents tell Discord which events your bot wants to receive. Since API v2, you must declare them both in code and in the developer portal to reduce unnecessary data transfer.

Q: How do I handle bots in thousands of servers? A: Use the built-in ShardingManager, which spawns separate processes per shard. Discord requires sharding for bots in 2,500+ guilds.

Q: Does Discord.js support voice? A: Yes, via the @discordjs/voice package, which handles joining channels, playing audio streams, and managing voice state.

Q: Is Discord.js free to use? A: Yes, it is open source under the Apache-2.0 license.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires