* cleanup(StreamDispatcher): remove old 'end' event * fix(StreamDispatcher): only listen to finish event once * refactor(VoiceWebSocket): use `connection.client` in favour of `connection.voiceManager.client` * fix(VoiceWebSocket): use `client.clearInterval` in favour of `clearInterval` * refactor: destructure EventEmitter * refactor: destructure EventEmitter from events * refactor: use EventEmitter.off in favour of EventEmitter.removeListener * style: order typings alphabetically * oops * fix indent * style: alphabetically organize imports * style: remove extra line * Revert "style: remove extra line" This reverts commit 96e182ed69cfba159ef69aba1d0b218002af67c6. * Revert "style: alphabetically organize imports" This reverts commit 02aee9b06d991731d08d552cf661c5e01343ec6a. * Revert "refactor: destructure EventEmitter from events" This reverts commit 9953b4d267b183e12dee52b284ce7188d67381f6. * Revert "refactor: destructure EventEmitter" This reverts commit 930d7751ab2ee902c8a80559ae9976f67ef6efb0. * Revert "fix(StreamDispatcher): only listen to finish event once" This reverts commit 485a6430a804aba7368e105e9f8bd0c093d7491d. * refactor: use .removeListener instead of .off |
||
|---|---|---|
| .github | ||
| docs | ||
| src | ||
| test | ||
| typings | ||
| .eslintrc.json | ||
| .gitattributes | ||
| .gitignore | ||
| .npmignore | ||
| .npmrc | ||
| .tern-project | ||
| jsdoc.json | ||
| LICENSE | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| tslint.json | ||
| webpack.config.js | ||
Table of contents
About
discord.js is a powerful Node.js module that allows you to easily interact with the Discord API.
- Object-oriented
- Predictable abstractions
- Performant
- 100% coverage of the Discord API
Installation
Node.js 11.0.0 or newer is required.
Ignore any warnings about unmet peer dependencies, as they're all optional.
Without voice support: npm install discordjs/discord.js
With voice support (@discordjs/opus): npm install discordjs/discord.js @discordjs/opus
With voice support (opusscript): npm install discordjs/discord.js opusscript
Audio engines
The preferred audio engine is @discordjs/opus, as it performs significantly better than opusscript. When both are available, discord.js will automatically choose @discordjs/opus. Using opusscript is only recommended for development environments where @discordjs/opus is tough to get working. For production bots, using @discordjs/opus should be considered a necessity, especially if they're going to be running on multiple servers.
Optional packages
- zlib-sync for WebSocket data compression and inflation (
npm install zlib-sync) - erlpack for significantly faster WebSocket data (de)serialisation (
npm install discordapp/erlpack) - One of the following packages can be installed for faster voice packet encryption and decryption:
- sodium (
npm install sodium) - libsodium.js (
npm install libsodium-wrappers)
- sodium (
- bufferutil for a much faster WebSocket connection (
npm install bufferutil) - utf-8-validate in combination with
bufferutilfor much faster WebSocket processing (npm install utf-8-validate)
Example usage
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('pong');
}
});
client.login('token');
Links
- Website (source)
- Documentation
- Guide (source) - this is still for stable
See also the Update Guide, including updated and removed items in the library. - Discord.js Discord server
- Discord API Discord server
- GitHub
- NPM
- Related libraries
Extensions
Contributing
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
documentation.
See the contribution guide if you'd like to submit a PR.
Help
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official Discord.js Server.

