Files
discord.js/packages/rest
Synbulat Biishev 1ab60f9da4 feat: support new username system (#9512)
* feat: support new username system

* docs(GuildMember#displayName): update

* fix(User#hasNewUsername): use User#discriminator

* feat(User#tag): add new username

* docs(User#tag): update

* docs(User#hasNewUsername): update

* docs: update

* feat(User#defaultAvatarURL): update

* feat: remove some newly added properties

* docs(User#discriminator): update

* docs(User#globalName): bad Copilot

* feat(User#displayName): return display name

* types(User#displayName): not a partial structure

* feat: add `calculateUserDefaultAvatarId` function

* docs(CND#defaultAvatar): update

* docs(CDN#defaultAvatar): update

* feat: change default avatar id to type

* feat: deprecate `User#tag`

* docs(CDN#defaultAvatar): update

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

* docs(User): update

Co-authored-by: Rodrigo Leitão <38259440+ImRodry@users.noreply.github.com>

* feat: update

* typing: update

Co-authored-by: Jan <66554238+vaporoxx@users.noreply.github.com>

* feat: change the param type to `Snowflake`

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: Rodrigo Leitão <38259440+ImRodry@users.noreply.github.com>
Co-authored-by: Jan <66554238+vaporoxx@users.noreply.github.com>
2023-06-08 18:16:42 +00:00
..
2023-05-03 02:14:22 +02:00
2022-09-02 22:07:19 +02:00
2023-05-03 02:14:22 +02:00
2022-07-22 01:32:19 +02:00
2023-05-03 02:14:22 +02:00
2023-04-02 01:55:39 +02:00
2022-09-08 01:46:41 +02:00
2023-05-23 20:14:15 +02:00
2022-06-19 13:19:24 +02:00


discord.js


Discord server npm version npm downloads Tests status Code coverage

Vercel Cloudflare Workers

About

@discordjs/rest is a module that allows you to easily make REST requests to the Discord API.

Installation

Node.js 18.12.0 or newer is required.

npm install @discordjs/rest
yarn add @discordjs/rest
pnpm add @discordjs/rest

Examples

Install all required dependencies:

npm install @discordjs/rest discord-api-types
yarn add @discordjs/rest discord-api-types
pnpm add @discordjs/rest discord-api-types

Send a basic message:

import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v10';

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

try {
	await rest.post(Routes.channelMessages(CHANNEL_ID), {
		body: {
			content: 'A message via REST!',
		},
	});
} catch (error) {
	console.error(error);
}

Create a thread from an existing message to be archived after 60 minutes of inactivity:

import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v10';

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

try {
	await rest.post(Routes.threads(CHANNEL_ID, MESSAGE_ID), {
		body: {
			name: 'Thread',
			auto_archive_duration: 60,
		},
	});
} catch (error) {
	console.error(error);
}

Send a basic message in an edge environment:

import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v10';

const rest = new REST({ version: '10', makeRequest: fetch }).setToken(TOKEN);

try {
	await rest.post(Routes.channelMessages(CHANNEL_ID), {
		body: {
			content: 'A message via REST from the edge!',
		},
	});
} catch (error) {
	console.error(error);
}

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.