You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
plugin-gateway: structure compatibility of equals() across structures (discord.js parity) #203
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
Add GuildChannel#equals (and decide whether it belongs on the base channel) and SoundboardSound#equals.
Align the signatures with discord.js where they differ (Sticker/GuildEmoji take other: X | unknown, Component/Embed/SoundboardSound accept the raw payload).
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.
Check the other structures that discord.js compares through other means for the same Diffable use.
Out of scope
Interaction-bound structures and ApplicationCommand.
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
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.
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.
SoundboardSound#equals. Compare soundId, name, volume, emojiId, emojiName, guildId, available and userId. Verify the field list against discord.js.
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.
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.
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.
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.
Activity
pullfrog commentedon Oct 5, 2026
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
Diffableonly matters for emojis and stickers.diff()inpackages/plugin-gateway/src/util/dispatch.ts:757is called twice, forGuildEmojisUpdateandGuildStickersUpdate. Both are matched byidand then compared withGuildEmoji#equals/Sticker#equals.messageUpdatedoes not useequals(). The handler atdispatch.ts:271takes the cached previous message throughpreviousOfand always emits[old, new]. ChangingMessage#equalstherefore cannot breakmessageUpdateemission. 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#equalsis already covered. It comes from@discordjs/structures(index.d.ts:378) andtests/bitfield.test.tsexercises it. It can be dropped from the table.equalscoverage in tests is thin. OnlyUser,Message,Component,PresenceandBitFieldhave anyequalstest.Sticker,GuildEmoji,Embed,Guild,Role,ActivityandGuildMemberhave none. The two that drivediff()(Sticker,GuildEmoji) are untested.GuildChannelMixin(structures/channels/mixins/GuildChannelMixin.ts), which is also mixed into threads.SoundboardSound(structures/soundboards/SoundboardSound.ts) has noequalseither.Proposed plan
Sticker#equalsandGuildEmoji#equalstakeother: X | unknown, as in discord.js. They returnfalsefor a non-matching or foreign argument instead of throwing.Message#equalsadds the optionalrawDataparameter.Component,EmbedandSoundboardSoundaccept the raw payload.Diffableas is. It already types the argument asnever.GuildChannel#equals.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 onGuildChannel.id,type, raw position,parentIdand the permission overwrites (same size, each matched by id throughPermissionOverwrites#equals, if that exists; otherwise add it).discord.jsis not installed in this repo. They should be checked against 14.27 before implementing.SoundboardSound#equals. ComparesoundId,name,volume,emojiId,emojiName,guildId,availableanduserId. Verify the field list against discord.js.Message#equalssemantics. My recommendation is to port the discord.js comparison: ids, author, content,nonce,tts, attachment and embed counts, plusmentions.everyoneand the timestamps whenrawDatais given. Reasons:pinnedand deep-equals embeds, which makes a pin change look like an edit.toJSON()withisDeepEqual.Guild,Role,User,Presence,ActivityandEmbedagainst discord.js field by field. Document the intentional extras, such asGuildMember#equals, which is not in the discord.js typings. Consider keeping it, since it is harmless.equalstest per structure (equal, different, wrong type ornull, raw payload where accepted), including thediff()path for emoji and sticker updates, so a signature change cannot silently break update emission.minorchangeset for@wolfstar/plugin-gateway(a behaviour change forMessage#equals, new methods otherwise). Runpnpm lint,pnpm build,pnpm typecheckandpnpm test. Update the type-level consumption test if the new signatures are public API.Questions for the maintainers
Message#equalsto the discord.js semantics, or should it stay deeper and only gain therawDataparameter?equalslive onGuildChannelMixinonly, as proposed?GuildMember#equalskept as an extension beyond discord.js parity?Once the
Message#equalsquestion is answered, this is one small PR. The remaining steps carry no open design questions.claude-sonnet-5-5| 𝕏