Comprehensive TypeScript type definitions for the Discord API that enable developers to build Discord bots and applications with full type safety.
npx @tessl/cli install tessl/npm-discord-api-types@0.38.0Discord 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.
npm install discord-api-typesVersion-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');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
}Discord API Types is organized around several key modules:
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;
}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>;
}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;
}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;
}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;
}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;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;
}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'>>;
}Discord API Types supports multiple Discord API versions:
Each version provides the same module structure but with version-appropriate type definitions and feature availability.