Top Related Projects
An API wrapper for Discord written in Python.
Java wrapper for the popular chat & VOIP service: Discord https://discord.com
An unofficial .Net wrapper for the Discord API (https://discord.com/)
Quick Overview
discord.js is a powerful Node.js module that allows you to interact with the Discord API easily. It provides a robust framework for creating Discord bots and applications, offering an object-oriented approach to handling Discord-related tasks.
Pros
- Extensive documentation and active community support
- Supports both Discord bot and OAuth2 application development
- Efficient handling of large-scale Discord operations
- Regular updates and maintenance
Cons
- Steep learning curve for beginners
- Requires understanding of asynchronous programming concepts
- Can be resource-intensive for very large bot implementations
- Some advanced features may require additional dependencies
Code Examples
Creating a simple Discord bot:
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] });
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('messageCreate', message => {
if (message.content === '!ping') {
message.reply('Pong!');
}
});
client.login('YOUR_BOT_TOKEN');
Sending an embed message:
const { EmbedBuilder } = require('discord.js');
const embed = new EmbedBuilder()
.setTitle('Example Embed')
.setColor(0x0099FF)
.setDescription('This is an example of a rich embed message')
.addFields(
{ name: 'Field 1', value: 'Value 1', inline: true },
{ name: 'Field 2', value: 'Value 2', inline: true }
);
message.channel.send({ embeds: [embed] });
Using slash commands:
const { SlashCommandBuilder } = require('@discordjs/builders');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const commands = [
new SlashCommandBuilder().setName('ping').setDescription('Replies with pong!'),
].map(command => command.toJSON());
const rest = new REST({ version: '9' }).setToken('YOUR_BOT_TOKEN');
rest.put(Routes.applicationGuildCommands(CLIENT_ID, GUILD_ID), { body: commands })
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);
Getting Started
-
Install discord.js:
npm install discord.js
-
Create a new Discord application and bot at the Discord Developer Portal.
-
Copy your bot token and use it in your code:
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.login('YOUR_BOT_TOKEN');
-
Run your bot:
node your_bot_file.js
Competitor Comparisons
An API wrapper for Discord written in Python.
Pros of discord.py
- Written in Python, which is often considered more beginner-friendly and easier to read
- Extensive documentation and a large community for support
- Asynchronous by default, making it efficient for handling multiple tasks
Cons of discord.py
- Slower execution speed compared to JavaScript
- Less frequent updates and potentially slower adoption of new Discord features
- Limited to Python ecosystem, whereas discord.js can leverage Node.js packages
Code Comparison
discord.py:
@client.event
async def on_message(message):
if message.content.startswith('!hello'):
await message.channel.send('Hello!')
discord.js:
client.on('messageCreate', message => {
if (message.content.startsWith('!hello')) {
message.channel.send('Hello!');
}
});
Both libraries offer similar functionality for basic bot operations. The syntax differs due to the language differences, with discord.py using Python's async/await syntax and discord.js using JavaScript's event-driven approach. discord.py's code is often more concise, while discord.js may offer more flexibility in terms of callback handling and promise chaining.
Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Pros of JDA
- Written in Java, offering strong typing and better performance for large-scale applications
- More comprehensive and feature-rich API, providing deeper integration with Discord's features
- Better suited for complex bot development with extensive functionality
Cons of JDA
- Steeper learning curve, especially for developers new to Java
- Less frequent updates compared to discord.js
- Larger codebase and potentially more complex setup process
Code Comparison
discord.js:
client.on('messageCreate', message => {
if (message.content === '!ping') {
message.reply('Pong!');
}
});
JDA:
public class PingCommand extends ListenerAdapter {
@Override
public void onMessageReceived(MessageReceivedEvent event) {
if (event.getMessage().getContentRaw().equals("!ping")) {
event.getChannel().sendMessage("Pong!").queue();
}
}
}
Both libraries offer similar functionality for basic bot operations, but JDA's code tends to be more verbose due to Java's nature. discord.js benefits from JavaScript's concise syntax, making it easier for quick prototyping and simpler bots. However, JDA's structure can be advantageous for larger, more complex projects where strong typing and object-oriented design are beneficial.
An unofficial .Net wrapper for the Discord API (https://discord.com/)
Pros of Discord.Net
- Built for C# and .NET, providing strong typing and better integration with Microsoft ecosystem
- Supports both synchronous and asynchronous programming models
- More comprehensive documentation and examples for .NET developers
Cons of Discord.Net
- Smaller community compared to discord.js, potentially leading to fewer third-party resources
- May have slower update cycles for new Discord API features
- Less suitable for developers primarily working with JavaScript or Node.js
Code Comparison
discord.js:
client.on('messageCreate', message => {
if (message.content === '!ping') {
message.reply('Pong!');
}
});
Discord.Net:
client.MessageReceived += async (s, e) =>
{
if (e.Message.Content == "!ping")
await e.Channel.SendMessageAsync("Pong!");
};
Both libraries offer similar functionality for handling Discord events and sending messages. Discord.js uses a more event-driven approach with callbacks, while Discord.Net leverages C#'s async/await pattern. The Discord.Net example demonstrates stronger typing with explicit message and channel objects.
The choice between these libraries largely depends on the developer's preferred language and ecosystem. discord.js is ideal for JavaScript developers and those working with Node.js, while Discord.Net caters to C# and .NET developers who value strong typing and Microsoft tooling integration.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
About
This repository contains multiple packages with separate releases. You can find the assembled Discord API wrapper at discord.js
. It is a powerful Node.js module that allows you to easily interact with the Discord API.
Packages
discord.js
(source) - A powerful Node.js module for interacting with the Discord API@discordjs/brokers
(source) - A collection of brokers for use with discord.js@discordjs/builders
(source) - A utility package for easily building Discord API payloads@discordjs/collection
(source) - A powerful utility data structure@discordjs/core
(source) - A thinly abstracted wrapper around the core components of the Discord API@discordjs/formatters
(source) - A collection of functions for formatting strings@discordjs/proxy
(source) - A wrapper around@discordjs/rest
for running an HTTP proxy@discordjs/rest
(source) - A module for interacting with the Discord REST API@discordjs/voice
(source) - A module for interacting with the Discord Voice API@discordjs/util
(source) - A collection of utility functions@discordjs/ws
(source) - A wrapper around Discord's gateway
Links
- Website (source)
- Documentation
- Guide (source) Also see the v13 to v14 Update Guide, which includes updated and removed items from the library.
- discord.js Discord server
- Discord API Discord server
- GitHub
- npm
- Related libraries
Extensions
Contributing
Please read through our contribution guidelines before starting a pull request. We welcome contributions of all kinds, not just code! If you're stuck for ideas, look for the good first issue label on issues in the repository. If you have any questions about the project, feel free to ask them on Discord. Before creating your own issue or pull request, always check to see if one already exists! Don't rush contributions, take your time and ensure you're doing it correctly.
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 join our Discord server.
Top Related Projects
An API wrapper for Discord written in Python.
Java wrapper for the popular chat & VOIP service: Discord https://discord.com
An unofficial .Net wrapper for the Discord API (https://discord.com/)
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot