Structures

Every Discord object is a class. They share a small base and form deep hierarchies for channels and interactions.

Every Discord object is a class. They share a small base and form deep hierarchies for channels and interactions.

Class tree (abridged)

Base
  BaseChannel
    PartialChannel
    PrivateChannel
    GuildChannel
      CategoryChannel
      ForumChannel
      MediaChannel
      GuildTextChannel
        NewsChannel
        ThreadChannel -> NewsThreadChannel
      GuildVoiceChannel
        StageChannel
        VoiceTextChannel
  Interaction
    CommandInteraction
    ComponentInteraction
    ModalSubmitInteraction
    AutocompleteInteraction
    PingInteraction
  User (extends PartialUser)
  Member
  Guild
  Message
  Role
  Invite, PermissionOverwrite, StageInstance, ThreadMember, VoiceState
  Entitlement, SKU, Subscription
  AutoModerationRule, GuildScheduledEvent
  GuildAuditLogEntry, GuildIntegration, GuildPreview, UnavailableGuild

Base gives every object an id, a createdAt getter (derived from the snowflake), and toJSON().

Cached vs partial

Athena caches what the gateway has shown it. When you access something it has not seen (a reaction on an old message, for example) you get a partial: PartialChannel, PartialUser, or an uncached-message shape. Guard with instanceof or the partial flag.

client.on('messageDelete', (message) => {
  if (message instanceof Message) {
    // full data
  } else {
    // only id, channel, guildID
  }
});

Channels

BaseChannel has type guards that narrow the union:

if (channel.isTextBased()) { /* has a messages cache + send helpers */ }
if (channel.isVoiceBased()) { /* GuildVoiceChannel | StageChannel | VoiceTextChannel */ }
if (channel.isThread()) { /* ThreadChannel | NewsThreadChannel */ }
if (channel.inGuild()) { /* any GuildChannel */ }

Text-based channels expose messages, createMessage, editMessage, deleteMessage, getMessage(s), getPins, reactions, sendTyping. channel.mention returns <#id>.

Interactions

Common methods on Interaction: defer, createMessage, createFollowup, editOriginalMessage, deleteOriginalMessage, getOriginalMessage, createModal, plus the isCommand/isComponent/isModal/isAutocomplete/isPing guards.

CommandInteraction adds typed option getters:

interaction.getString('name');           // string | null
interaction.getRequiredString('name');   // string, throws if missing
interaction.getInteger('count');
interaction.getNumber('amount');
interaction.getBoolean('flag');
interaction.getUser('user');             // and getMember
interaction.getChannel('channel');
interaction.getRole('role');
interaction.getMentionable('target');
interaction.getAttachment('file');
interaction.inGuild();                   // narrows to GuildCommandInteraction

ComponentInteraction adds isButton, isStringSelect, isChannelSelect, isRoleSelect, isUserSelect, isMentionableSelect, the selected values, deferUpdate, and editParent. ModalSubmitInteraction exposes fields.

Useful members

StructureHighlights
Guildmembers, channels, roles, threads, voiceStates, permissionsOf(member), plus a large REST mirror. Async fetchMember(id).
MemberaddRole, removeRole, ban, kick, edit, permissions, highestRole, displayColor, displayName()
UserdisplayName(), avatarURL, dynamicAvatarURL(), bannerURL, mention, getDMChannel
Messageedit, delete, pin, addReaction, crosspost, channelMentions, cleanContent, jumpLink, poll, messageSnapshots
Roledelete, edit, editPosition, comparePosition, iconURL, mention

Collections

Collection<Value> extends Map and is used for every cache (guild.members, client.users, channel.messages, ...). It adds add, update, remove, find, filter, map, every, some, reduce, random. For very large bots you can swap the underlying store; see Caching and memory.

Bitfields

PermissionBitfield, GatewayIntentsBitfield, MessageFlagBitfield, ChannelFlagBitfield, SKUFlagBitfield. All support has, add, remove, and json. PermissionBitfield adds isAdmin() and missing(...).