Co-authored-by: monbrey <rsm999@uowmail.edu.au>
* Added `DiscordCertifiedModerator` flag to UserFlags
* Updated types for Message Components
* Added `disabled` to APISelectMenuCompponent
* Cleaned up Buttons types, making them stricter based on the `style` you provide
BREAKING CHANGE: `APISelectOption` has been renamed to `APISelectMenuOption`
BREAKING CHANGE: APISelectMenuOption#default is now properly marked as optional
* Updated OAuth2 Application types
BREAKING CHANGE: `APIApplication#owner` is now marked as optional, per the docs
* Correct APIAuditLogChangeKeyNick's key
BREAKING CHANGE: This renames APIAuditLogChangeKeyNick's key from `mute` to `nick`
* Add `application_id` to APIMessage
* Correct type of `id` and `user_id` in APIThreadMember
BREAKING CHANGE: The type of `id` and `user_id` in APIThreadMember are now marked as optional; read the TSDoc for when it's actually optional
* Correctly version API route in RouteBases
BREAKING CHANGE: This changes the `RouteBases.api` to be versioned based on the API version you're importing. **Make sure to update your code to handle that**
* Added new guild features
ref: 4d36e533cf
* Cleaned up interaction types
BREAKING CHANGE: While this shouldn't be necessary, this is a warning that types for interactions HAVE changed and you may need to update your code. For the most part, the types *should* be the same, more accurate and strictly typed. You will also see that every type of interaction has a Guild/DM counterpart exported (ex: APIApplicationCommandGuildInteraction vs APIApplicationCommandInteraction, where the former has all the guild properties, while the latter has all properties that depend on context marked as optional).
* Add TSD testing support in CI
This is mostly useful for testing unions of types
* Add message property to MessageComponent interactions
Discord API Types
Simple type definitions for the Discord API.
Installation
Install with npm / yarn / pnpm:
npm install discord-api-types
yarn add discord-api-types
pnpm add discord-api-types
Usage
You can only import this module by specifying the API version you want to target. Append /v* to the import path, where the * represents the API version. Below are some examples
const { APIUser } = require('discord-api-types/v9');
// TypeScript/ES Module support
import { APIUser } from 'discord-api-types/v9';
You may also import just certain parts of the module that you need. The possible values are: globals, gateway, gateway/v*, payloads, payloads/v*, rest, rest/v*, rpc, rpc/v*, utils, utils/v*, voice, and voice/v*. Below are some examples
const { GatewayVersion } = require('discord-api-types/gateway/v9');
// TypeScript/ES Module support
import { GatewayVersion } from 'discord-api-types/gateway/v9';
Note: The
v*exports (discord-api-type/v*) include the appropriate version ofgateway,payloads,rest,rpc, andutilsyou specified, alongside theglobalsexports
Deno
We also provide typings compatible with the deno runtime. You have 3 ways you can import them:
- Directly from GitHub
// Importing a specific API version
import { APIUser } from 'https://raw.githubusercontent.com/discordjs/discord-api-types/main/deno/v9.ts';
- From deno.land/x
// Importing a specific API version
import { APIUser } from 'https://deno.land/x/discord_api_types/v9.ts';
- From skypack.dev
// Importing a specific API version
import { APIUser } from 'https://cdn.skypack.dev/discord-api-types/v9?dts';
Project Structure
The exports of each API version is split into three main parts:
-
Everything exported with the
APIprefix represents a payload you may get from the REST API or the Gateway. -
Everything exported with the
Gatewayprefix represents data that ONLY comes from or is directly related to the Gateway. -
Everything exported with the
RESTprefix represents data that ONLY comes from or is directly related to the REST API.-
For endpoint options, they will follow the following structure:
REST<HTTP Method><Type><Query|(JSON|FormData)Body|Result>where the type represents what it will return.-
For example,
RESTPostAPIChannelMessageJSONBodyorRESTGetAPIGatewayBotInfoResult. -
Some exported types (specifically OAuth2 related ones) may not respect this entire structure due to the nature of the fields. They will start with either
RESTOAuth2or with something similar toREST<HTTP Method>OAuth2
-
-
If a type ends with
Result, then it represents the expected result by calling its accompanying route.- Types that are exported as
neverusually mean the result will be a204 No Content, so you can safely ignore it. This does not account for errors.
- Types that are exported as
-
-
Anything else that is miscellaneous will be exported based on what it represents (for example the
RESTroute object). -
There may be types exported that are identical for all versions. These will be exported as is and can be found in the
globalsfile. They will still be prefixed accordingly as described above.
Warning: This package documents just KNOWN (and documented) properties. Anything that isn't documented will NOT be added to this package (unless said properties are in an open Pull Request to Discord's API Documentation repository or known through other means and have received the green light to be used). For clarification's sake, this means that properties that are only known through the process of data mining and have not yet been confirmed in a way as described will NOT be included.