mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
* feat: add @discordjs/core * chore: lint * chore: add all gateway events * chore: add the rest of the rest routes * chore: cleanup gateway * chore: rename gateway to client * chore: rename gateway to client * fix: don't spread unless we need to * refactor: use classes and make requested changes * chore: show shardId on emit * chore: add interface for intrinsic props * refactor: scope dispatch data instead of spreading * chore: add utility for uploading files for messages and interactions * feat: finish up form data handling * chore: add readme * chore: update api-extractor stuff * chore: bump deps * chore: make requested changes * chore: make requested changes * Update package.json * chore: make requested changes * fix: add missing interaction responses * chore: make some requested changes * chore: remove `return await` * chore: use autoModeration instead of automod * refactor: use snowflakes and -types results * chore: sort imports, fix return type on editUserVoiceState * chore: rename bots to users * feat: add automod dispatch events * refactor: move templates and members into guild * fix: use users instead of bots in api class * chore: imports * chore: make requested changes * fix: don't make files required on interaction replies * fix: rename sendMessage to createMessage * feat: add application command routes * feat: add webhook.execute overloads and options to invites.get * chore: use create prefixes * chore: seperate interaction params * chore: use Id * chore: make requested changes * chore: make requested changes * chore: make requested changes * chore: for -> from * Apply suggestions from code review Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * Update packages/core/README.md Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * chore: make requested changes * chore: update -types * chore: bump vitest * fix: sticker uploading * fix: lockfile * chore: make requested changes * chore: make requested changes * Update packages/core/src/api/applicationCommands.ts Co-authored-by: Almeida <almeidx@pm.me> * Apply suggestions from code review Co-authored-by: Aura Román <kyradiscord@gmail.com> * Update packages/core/README.md Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: almeidx <almeidx@pm.me> Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: Aura Román <kyradiscord@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
About
@discordjs/core is a thinly abstracted wrapper around the "core" components of the Discord API: REST, and gateway.
Installation
Node.js 16.9.0 or newer is required.
npm install @discordjs/core
yarn add @discordjs/core
pnpm add @discordjs/core
Example usage
import { REST } from '@discordjs/rest';
import { WebSocketManager } from '@discordjs/ws';
import { GatewayIntentBits, InteractionType, MessageFlags, createClient } from '@discordjs/core';
// Create REST and WebSocket managers directly
const rest = new REST({ version: '10' }).setToken(token);
const ws = new WebSocketManager({
token,
intents: GatewayIntentBits.GuildMessages | GatewayIntentBits.MessageContent,
rest,
});
// Create a client to emit relevant events.
const client = createClient({ rest, ws });
// Listen for interactions
// Each event contains an `api` prop along with the event data that allows you to interface with the Discord REST API
client.on('interactionCreate', async ({ interaction, api }) => {
if (!(interaction.type === InteractionType.ApplicationCommand) || interaction.data.name !== 'ping') {
return;
}
await api.interactions.reply(interaction.id, interaction.token, { content: 'Pong!', flags: MessageFlags.Ephemeral });
});
// Listen for the ready event
client.on('ready', () => console.log('Ready!'));
// Start the WebSocket connection.
ws.connect();
Independent REST API Usage
// Create REST instance
const rest = new REST({ version: '10' }).setToken(token);
// Pass into API
const api = new API(rest);
// Fetch a guild using the API wrapper
const guild = await api.guilds.get('1234567891011');
Links
- Website (source)
- Documentation
- Guide (source) 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
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.