Skip to content

plugin-gateway: structure compatibility of equals() across structures (discord.js parity) #203

Closed

Description

@RedStar071

Context

In discord.js equals() is a convention shared by many structures, not a feature of Message. It is used for change detection (update events) and by user code. While drafting the Message type-parity spec (docs/superpowers/specs/2026-10-05-message-types-parity-design.md) the question of porting discord.js' Message#equals came up. It is off-topic there, so it is tracked here for all structures at once.

Where equals stands (discord.js 14.27 typings vs @wolfstar/plugin-gateway)

discord.js plugin-gateway
Activity#equals(activity) present, accepts null | undefined
Component#equals(other) present
Embed#equals(other) present
Guild#equals(guild) present
GuildEmoji#equals(other) present
Message#equals(message, rawData?) present, but equals(message: Message | APIMessage), no rawData, and a different comparison (compares pinned, deep-equals raw embeds and attachments; discord.js compares IDs, author, content, nonce, tts, attachment and embed counts and, with rawData, mentions.everyone and the timestamps)
Presence#equals(presence) present, accepts null | undefined
Role#equals(role) present
Sticker#equals(other) present, typed Sticker only
User#equals(user) present
GuildChannel#equals(channel) missing
SoundboardSound#equals(other) missing
ApplicationEmoji#equals(other) no ApplicationEmoji structure here
BitField#equals(bit) to check against the bit fields used here
ApplicationCommand#equals(...) out of scope (interactions, see the parity scope)

GuildMember#equals exists here but is not in the discord.js typings.

Proposal

  1. Add GuildChannel#equals (and decide whether it belongs on the base channel) and SoundboardSound#equals.
  2. Align the signatures with discord.js where they differ (Sticker/GuildEmoji take other: X | unknown, Component/Embed/SoundboardSound accept the raw payload).
  3. Decide on Message#equals: port discord.js' semantics (including rawData), or keep the current deeper comparison and only add the parameter. The update-event diffing in util/dispatch.ts (Diffable) relies on equals, so whichever is chosen must keep messageUpdate emission correct.
  4. Check the other structures that discord.js compares through other means for the same Diffable use.

Out of scope

Interaction-bound structures and ApplicationCommand.

Activity

  1. pullfrog commented on Oct 5, 2026

    @pullfrog
    Contributor

    Assessment

    Actionable, but smaller than the table suggests, and it needs a few decisions from the maintainers first. Nothing here has been implemented.

    Findings from the code

    • Diffable only matters for emojis and stickers. diff() in packages/plugin-gateway/src/util/dispatch.ts:757 is called twice, for GuildEmojisUpdate and GuildStickersUpdate. Both are matched by id and then compared with GuildEmoji#equals / Sticker#equals.
    • messageUpdate does not use equals(). The handler at dispatch.ts:271 takes the cached previous message through previousOf and always emits [old, new]. Changing Message#equals therefore cannot break messageUpdate emission. This resolves the concern in point 3 of the proposal. It is also the case for guild, role, channel, member, user and presence updates.
    • BitField#equals is already covered. It comes from @discordjs/structures (index.d.ts:378) and tests/bitfield.test.ts exercises it. It can be dropped from the table.
    • Existing equals coverage in tests is thin. Only User, Message, Component, Presence and BitField have any equals test. Sticker, GuildEmoji, Embed, Guild, Role, Activity and GuildMember have none. The two that drive diff() (Sticker, GuildEmoji) are untested.
    • Missing structures:
      • Guild channels use GuildChannelMixin (structures/channels/mixins/GuildChannelMixin.ts), which is also mixed into threads.
      • SoundboardSound (structures/soundboards/SoundboardSound.ts) has no equals either.

    Proposed plan

    1. Signatures (non-breaking widening).
      • Sticker#equals and GuildEmoji#equals take other: X | unknown, as in discord.js. They return false for a non-matching or foreign argument instead of throwing.
      • Message#equals adds the optional rawData parameter.
      • Component, Embed and SoundboardSound accept the raw payload.
      • Keep Diffable as is. It already types the argument as never.
    2. GuildChannel#equals.
      • Add it to GuildChannelMixin, since the mixin already covers every guild channel type including threads. Do not add it to the base channel: DM channels have no position, parent or overwrites in discord.js, and discord.js defines it on GuildChannel.
      • Compare id, type, raw position, parentId and the permission overwrites (same size, each matched by id through PermissionOverwrites#equals, if that exists; otherwise add it).
      • Accept the raw payload as well.
      • I am recalling the discord.js semantics from memory because discord.js is not installed in this repo. They should be checked against 14.27 before implementing.
    3. SoundboardSound#equals. Compare soundId, name, volume, emojiId, emojiName, guildId, available and userId. Verify the field list against discord.js.
    4. Message#equals semantics. My recommendation is to port the discord.js comparison: ids, author, content, nonce, tts, attachment and embed counts, plus mentions.everyone and the timestamps when rawData is given. Reasons:
      • It is a parity library.
      • Nothing internal depends on the current deeper comparison.
      • The current version compares pinned and deep-equals embeds, which makes a pin change look like an edit.
      • Users who want the deeper check can use toJSON() with isDeepEqual.
      • This is a behaviour change for the public method, so it needs a changeset describing it.
    5. Audit other structures (point 4 of the proposal). Check Guild, Role, User, Presence, Activity and Embed against discord.js field by field. Document the intentional extras, such as GuildMember#equals, which is not in the discord.js typings. Consider keeping it, since it is harmless.
    6. Tests. Add one equals test per structure (equal, different, wrong type or null, raw payload where accepted), including the diff() path for emoji and sticker updates, so a signature change cannot silently break update emission.
    7. Housekeeping. Add a minor changeset for @wolfstar/plugin-gateway (a behaviour change for Message#equals, new methods otherwise). Run pnpm lint, pnpm build, pnpm typecheck and pnpm test. Update the type-level consumption test if the new signatures are public API.

    Questions for the maintainers

    • Is it acceptable to switch Message#equals to the discord.js semantics, or should it stay deeper and only gain the rawData parameter?
    • Should the channel equals live on GuildChannelMixin only, as proposed?
    • Is GuildMember#equals kept as an extension beyond discord.js parity?

    Once the Message#equals question is answered, this is one small PR. The remaining steps carry no open design questions.

    Pullfrog  | Implement plan ➔ | View workflow run | via Pullfrog | Using claude-sonnet-5-5 | 𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions