or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

api-payloads.mdgateway-events.mdglobal-types.mdindex.mdinteractions.mdrest-api.mdrpc.mdutilities.mdvoice-gateway.md
tile.json

tessl/npm-discord-api-types

Comprehensive TypeScript type definitions for the Discord API that enable developers to build Discord bots and applications with full type safety.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/discord-api-types@0.38.x

To install, run

npx @tessl/cli install tessl/npm-discord-api-types@0.38.0

index.mddocs/

Discord API Types

Discord API Types is a comprehensive TypeScript type definition library for the Discord API that enables developers to build Discord bots and applications with full type safety. It provides complete type coverage for all Discord API endpoints, gateway events, payloads, interactions, and utilities across multiple API versions.

Package Information

  • Package Name: discord-api-types
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install discord-api-types
  • Documentation: https://discord-api-types.dev

Core Imports

Version-specific imports (recommended):

import { APIUser, APIGuild, ChannelType } from 'discord-api-types/v10';
import { GatewayOpcodes } from 'discord-api-types/gateway/v10';
import { Routes } from 'discord-api-types/rest/v10';

Module-specific imports:

import { Snowflake, FormattingPatterns } from 'discord-api-types/globals';
import { Utils } from 'discord-api-types/utils/v10';

For CommonJS:

const { APIUser, APIGuild, ChannelType } = require('discord-api-types/v10');
const { Routes } = require('discord-api-types/rest/v10');

Basic Usage

import { 
  APIUser, 
  APIGuild, 
  ChannelType,
  Routes 
} from 'discord-api-types/v10';
import { GatewayOpcodes } from 'discord-api-types/gateway/v10';
import { Utils } from 'discord-api-types/utils/v10';

// Type-safe Discord objects
const user: APIUser = {
  id: '123456789012345678',
  username: 'discord-user',
  discriminator: '0001',
  avatar: null,
  bot: false,
  system: false,
  mfa_enabled: false,
  banner: null,
  accent_color: null,
  locale: 'en-US',
  verified: true,
  email: null,
  flags: 0,
  premium_type: 0,
  public_flags: 0
};

// REST API route building
const channelRoute = Routes.channel('123456789012345678');
const messagesRoute = Routes.channelMessages('123456789012345678');

// Gateway opcode handling
if (payload.op === GatewayOpcodes.Dispatch) {
  // Handle gateway event
}

// Type guards for interactions
if (Utils.isChatInputApplicationCommandInteraction(interaction)) {
  // interaction is now typed as ChatInputApplicationCommandInteraction
}

Architecture

Discord API Types is organized around several key modules:

  • Versioned APIs: Type definitions for specific Discord API versions (v6, v8, v9, v10)
  • Global Types: Core types used across all modules (Snowflake, Permissions, formatting patterns)
  • Gateway System: WebSocket event types and opcodes for real-time Discord communication
  • Payload Types: Complete object definitions for all Discord entities (users, guilds, channels, messages)
  • REST API: HTTP endpoint types and route builders for Discord's REST API
  • Interaction System: Application commands, message components, and modals
  • Utility Functions: Type guards and helper functions for working with Discord types
  • Specialized APIs: RPC and voice gateway types for advanced Discord features

Capabilities

Global Types and Utilities

Core types and patterns used throughout the Discord API, including Snowflake IDs, permission handling, and message formatting utilities.

type Snowflake = string;
type Permissions = string;

interface FormattingPatterns {
  User: RegExp;
  Channel: RegExp;
  Role: RegExp;
  SlashCommand: RegExp;
  Emoji: RegExp;
  Timestamp: RegExp;
}

Global Types

Gateway and WebSocket Events

Real-time Discord communication through WebSocket connections, including all gateway events, opcodes, and presence management.

enum GatewayOpcodes {
  Dispatch = 0,
  Heartbeat = 1,
  Identify = 2,
  PresenceUpdate = 3,
  VoiceStateUpdate = 4,
  Resume = 6,
  Reconnect = 7,
  RequestGuildMembers = 8,
  InvalidSession = 9,
  Hello = 10,
  HeartbeatAck = 11
}

interface GatewayReadyDispatchData {
  v: number;
  user: APIUser;
  guilds: APIUnavailableGuild[];
  session_id: string;
  resume_gateway_url: string;
  shard?: [number, number];
  application: Partial<APIApplication>;
}

Gateway Events

Discord API Payloads

Complete type definitions for all Discord objects including users, guilds, channels, messages, roles, and permissions.

interface APIUser {
  id: Snowflake;
  username: string;
  discriminator: string;
  global_name?: string | null;
  avatar: string | null;
  bot?: boolean;
  system?: boolean;
  mfa_enabled?: boolean;
  banner?: string | null;
  accent_color?: number | null;
  locale?: string;
  verified?: boolean;
  email?: string | null;
  flags?: UserFlags;
  premium_type?: UserPremiumType;
  public_flags?: UserFlags;
  avatar_decoration?: string | null;
}

interface APIGuild {
  id: Snowflake;
  name: string;
  icon: string | null;
  icon_hash?: string | null;
  splash: string | null;
  discovery_splash: string | null;
  owner?: boolean;
  owner_id: Snowflake;
  permissions?: Permissions;
  region?: string | null;
  afk_channel_id: Snowflake | null;
  afk_timeout: number;
  widget_enabled?: boolean;
  widget_channel_id?: Snowflake | null;
  verification_level: GuildVerificationLevel;
  default_message_notifications: GuildDefaultMessageNotifications;
  explicit_content_filter: GuildExplicitContentFilter;
  roles: APIRole[];
  emojis: APIEmoji[];
  features: GuildFeature[];
  mfa_level: GuildMFALevel;
  application_id: Snowflake | null;
  system_channel_id: Snowflake | null;
  system_channel_flags: GuildSystemChannelFlags;
  rules_channel_id: Snowflake | null;
  max_presences?: number | null;
  max_members?: number;
  vanity_url_code: string | null;
  description: string | null;
  banner: string | null;
  premium_tier: GuildPremiumTier;
  premium_subscription_count?: number;
  preferred_locale: string;
  public_updates_channel_id: Snowflake | null;
  max_video_channel_users?: number;
  max_stage_video_channel_users?: number;
  approximate_member_count?: number;
  approximate_presence_count?: number;
  welcome_screen?: APIGuildWelcomeScreen;
  nsfw_level: GuildNSFWLevel;
  stickers?: APISticker[];
  premium_progress_bar_enabled: boolean;
  safety_alerts_channel_id: Snowflake | null;
}

API Payloads

REST API and Route Building

HTTP endpoint types and utilities for making requests to Discord's REST API, including route builders and CDN URLs.

interface Routes {
  applicationCommands(applicationId: Snowflake): `/applications/${string}/commands`;
  channel(channelId: Snowflake): `/channels/${string}`;
  channelMessages(channelId: Snowflake): `/channels/${string}/messages`;
  guild(guildId: Snowflake): `/guilds/${string}`;
  guildMembers(guildId: Snowflake): `/guilds/${string}/members`;
  user(userId: Snowflake): `/users/${string}`;
  webhook(webhookId: Snowflake, webhookToken?: string): string;
}

interface CDNRoutes {
  userAvatar(userId: Snowflake, userAvatar: string, format?: ImageFormat): string;
  guildIcon(guildId: Snowflake, guildIcon: string, format?: ImageFormat): string;
  emoji(emojiId: Snowflake, format?: ImageFormat): string;
  sticker(stickerId: Snowflake): string;
}

REST API

Interactions and Application Commands

Modern Discord interaction system including slash commands, message components, modals, and context menus.

interface APIApplicationCommand {
  id: Snowflake;
  type?: ApplicationCommandType;
  application_id: Snowflake;
  guild_id?: Snowflake;
  name: string;
  name_localizations?: LocalizationMap | null;
  description: string;
  description_localizations?: LocalizationMap | null;
  options?: APIApplicationCommandOption[];
  default_member_permissions?: Permissions | null;
  dm_permission?: boolean;
  default_permission?: boolean | null;
  nsfw?: boolean;
  version: Snowflake;
}

interface APIInteraction {
  id: Snowflake;
  application_id: Snowflake;
  type: InteractionType;
  data?: APIInteractionData;
  guild_id?: Snowflake;
  channel?: Partial<APIChannel>;
  channel_id?: Snowflake;
  member?: APIInteractionGuildMember;
  user?: APIUser;
  token: string;
  version: number;
  message?: APIMessage;
  app_permissions?: Permissions;
  locale?: string;
  guild_locale?: string;
}

Interactions

Utility Functions and Type Guards

Helper functions and type guards for working with Discord types and interactions safely.

function isDMInteraction(interaction: APIInteraction): boolean;
function isGuildInteraction(interaction: APIInteraction): boolean;
function isChatInputApplicationCommandInteraction(interaction: APIInteraction): boolean;
function isMessageComponentInteraction(interaction: APIInteraction): boolean;
function isLinkButton(component: APIMessageComponent): boolean;
function isInteractionButton(component: APIMessageComponent): boolean;

Utilities

Voice Gateway

Voice connection types and opcodes for Discord voice channels and voice gateway communication.

enum VoiceOpcodes {
  Identify = 0,
  SelectProtocol = 1,
  Ready = 2,
  Heartbeat = 3,
  SessionDescription = 4,
  Speaking = 5,
  HeartbeatAck = 6,
  Resume = 7,
  Hello = 8,
  Resumed = 9,
  ClientsConnect = 11,
  ClientDisconnect = 13
}

interface VoiceIdentifyData {
  server_id: Snowflake;
  user_id: Snowflake;
  session_id: string;
  token: string;
  max_dave_protocol_version?: number;
}

Voice Gateway

RPC (Rich Presence Client)

Rich Presence Client types for Discord RPC applications and game integrations.

enum RPCCommands {
  Authorize = 'AUTHORIZE',
  Authenticate = 'AUTHENTICATE',
  GetGuilds = 'GET_GUILDS',
  GetChannels = 'GET_CHANNELS',
  Subscribe = 'SUBSCRIBE',
  Unsubscribe = 'UNSUBSCRIBE',
  SetActivity = 'SET_ACTIVITY'
}

interface RPCSetActivityArgs {
  pid: number;
  activity?: Partial<Omit<GatewayActivity, 'created_at' | 'id'>>;
}

RPC

API Versions

Discord API Types supports multiple Discord API versions:

  • v10 (Current/Recommended): Complete modern Discord API with all latest features
  • v9 (Previous): Legacy support with most modern features
  • v8/v6 (Legacy): Historical versions for backwards compatibility

Each version provides the same module structure but with version-appropriate type definitions and feature availability.