A powerful JavaScript library for interacting with the Discord API
Find a file
2022-10-08 17:55:01 +02:00
.github ci: update workflow for tags 2022-10-08 16:33:37 +02:00
.husky chore: removing building website from pre-commit 2022-10-06 12:36:26 +02:00
.vscode feat: web-components (#8715) 2022-10-07 06:56:13 +02:00
.yarn fix: cliff.toml styling (#8716) 2022-10-07 13:57:48 +02:00
packages chore: update readmes 2022-10-08 17:55:01 +02:00
.commitlintrc.json chore: disable scope-case rule for commitlint (#7507) 2022-02-20 13:35:20 +01:00
.dockerignore feat: proxy container (#8000) 2022-06-17 23:29:50 +02:00
.eslintrc.json refactor: use eslint-config-neon for packages. (#8579) 2022-09-01 20:50:16 +02:00
.gitattributes According to the spec just this should work 2017-04-19 17:55:00 +02:00
.gitignore chore: move deps to root and some miscellaneous changes (#8129) 2022-06-21 15:15:38 +02:00
.lintstagedrc.json feat: web-components (#8715) 2022-10-07 06:56:13 +02:00
.prettierrc.json chore: monorepo setup (#7175) 2022-01-07 17:18:25 +01:00
.yarnrc.yml fix: cliff.toml styling (#8716) 2022-10-07 13:57:48 +02:00
codecov.yml feat: codecov (#8219) 2022-07-03 15:33:18 +02:00
LICENSE chore: add license to root 2022-07-19 20:11:23 +02:00
package.json fix: cliff.toml styling (#8716) 2022-10-07 13:57:48 +02:00
README.md chore: update readmes 2022-10-08 17:55:01 +02:00
tsconfig.eslint.json refactor: move all the config files to root (#8033) 2022-06-07 12:35:19 +02:00
tsconfig.json build: refactor build system (#8324) 2022-07-20 16:36:42 +02:00
tsup.config.js build: switch to esbuild-plugin-version-injector for injecting version strings (#8723) 2022-10-08 02:54:45 +02:00
turbo.json feat: astro guide (#8714) 2022-10-06 23:53:35 +02:00
vitest.config.ts chore: bump vitest and add @vitest/coverage-c8 (#8507) 2022-08-17 09:44:21 +02:00
yarn.lock chore: deps 2022-10-08 16:55:34 +02:00


discord.js


Discord server npm version npm downloads Tests status Code coverage

Vercel

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 16.9.0 or newer is required.

npm install discord.js
yarn add discord.js
pnpm add discord.js

Optional packages

  • zlib-sync for WebSocket data compression and inflation (npm install zlib-sync)
  • erlpack for significantly faster WebSocket data (de)serialisation (npm install discord/erlpack)
  • bufferutil for a much faster WebSocket connection (npm install bufferutil)
  • utf-8-validate in combination with bufferutil for much faster WebSocket processing (npm install utf-8-validate)
  • @discordjs/voice for interacting with the Discord Voice API (npm install @discordjs/voice)

Example usage

Install discord.js:

npm install discord.js
yarn add discord.js
pnpm add discord.js

Register a slash command against the Discord API:

const { REST, Routes } = require('discord.js');

const commands = [
	{
		name: 'ping',
		description: 'Replies with Pong!',
	},
];

const rest = new REST({ version: '10' }).setToken('token');

(async () => {
	try {
		console.log('Started refreshing application (/) commands.');

		await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands });

		console.log('Successfully reloaded application (/) commands.');
	} catch (error) {
		console.error(error);
	}
})();

Afterwards we can create a quite simple example bot:

const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.on('ready', () => {
	console.log(`Logged in as ${client.user.tag}!`);
});

client.on('interactionCreate', async (interaction) => {
	if (!interaction.isChatInputCommand()) return;

	if (interaction.commandName === 'ping') {
		await interaction.reply('Pong!');
	}
});

client.login('token');

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.