Skip to content

feat: bring gateway users, members and roles to discord.js parity - #97

Merged
RedStar071 merged 2 commits into
feat/gateway-hardeningfrom
feat/users-members-roles
Sep 25, 2026
Merged

RedStar071 merged 2 commits into
feat/gateway-hardeningfrom
feat/users-members-roles

Conversation

@RedStar071

Copy link
Copy Markdown
Member

Stacked on #95.

🔗 Linked issue

Related to #54 (phase 5 of the roadmap).

🧭 Context

Until now User, GuildMember and Role were thin wrappers exposing a handful of getters. A bot moving from discord.js had no way to add a role, time someone out, check whether it may kick a member, or set its own activity without dropping to raw REST calls. This phase covers what discord.js offers on those three entities and their managers.

📚 Description

Every API field is exposed, the CDN helpers (banner, avatar decoration, guild tag badge, role icon) come from @discordjs/rest, and the REST methods match discord.js's names.

The one systematic difference is async relations. discord.js reads member.permissions, member.kickable or member.roles.highest synchronously from its in-memory cache. Here the cache can be Redis, so they become fetchPermissions(), fetchKickable() and roles.fetchHighest(). They read the cache first and hit the API on a miss. For permissions, only the member's roles and @everyone are fetched, not every role of the guild.

Other choices worth a look:

  • client.user is now a ClientUser. Its setPresence sends the update on every shard the gateway manages, or on the ones passed. The bot's own USER_UPDATE patches it in place instead of swapping it for a plain User.
  • createDM always calls the API. Discord returns the existing channel when there is one, and without a sync cache there is nothing cheap to check first, so discord.js's force option has no equivalent.
  • Role#permissions is a PermissionsBitField instead of a bigint. It's a breaking change on an unreleased package, called out in the changeset as minor.
  • Member ban, bulkBan and prune are in, since discord.js has them on GuildMemberManager. The ban list itself (GuildBanManager) stays in the later moderation phase.
  • tsconfig.base.json moves lib to ES2023 for toSorted, which every Node version the packages support has.

Not ported, deliberately: member.voice and member.presence (phase 10), permissionsIn(channel) (phase 8, it needs overwrites), and Role#members, which would need every member of the guild.

Key changes

Area Change
User All fields, tag, banner/decoration/badge URLs, createDM/deleteDM/send, fetch, equals
ClientUser edit/setUsername/setAvatar/setBanner, setPresence/setStatus/setActivity/setAFK
GuildMember All fields, roles, fetchPermissions, fetchManageable/Kickable/Bannable/Moderatable, edit, timeout, kick, ban, DM helpers
Role PermissionsBitField, colors, icon, tags, flags, comparePositionTo, edit/set*, setPosition, delete
Managers GuildMemberRoleManager (new), GuildMemberManager list/search/add/edit/kick/ban/prune, RoleManager CRUD/positions/member counts, UserManager DMs

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation change
  • Workflow / CI change

Pre-flight Checklist

  • I have read the Contributing Guidelines (if applicable)
  • My code follows the code style of this project
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly
  • I added a changeset with pnpm changeset (or pnpm changeset add --empty if no release is needed). See .changeset/README.md.

🤖 AI disclosure: Wolfstar Agent Kit modified this description. My AI open-source policy.

@coldtea-pr-lens

coldtea-pr-lens Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

◈ PR Lens

PR Lens paused analysis for this repository — the fair-use limit was reached. It resumes automatically at 2026-09-25T18:00:00.000Z.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

One correctness issue found: Role#setPosition() returns data that can silently diverge from what's actually cached.

Reviewed changes

Reviewed the full diff (19 files, 1 commit 4989c45): verified every new discord-api-types REST payload shape against the vendored type definitions, ran the new/updated test suites (37/37 pass), and typechecked the package clean.

  • ClientUser (new): profile edit and presence (setPresence/setStatus/setActivity/setAFK), sent on every shard or a chosen subset. client.user is now typed ClientUser | null; USER_UPDATE for the bot's own ID patches it in place instead of replacing it with a plain User.
  • GuildMember: full field surface, a roles getter returning a new GuildMemberRoleManager, async fetchPermissions/fetchManageable/fetchKickable/fetchBannable/fetchModeratable, edit/timeout/kick/ban, DM helpers, equals.
  • Role: permissions is now Readonly<PermissionsBitField> instead of bigint (breaking, called out in the changeset as minor since the package is unreleased), colors/icon/tags/flags, comparePositionTo, edit/set*, setPosition, delete, equals.
  • Managers: GuildMemberManager gains list/search/add/edit/editMe/kick/ban/unban/bulkBan/prune/addRole/removeRole; RoleManager gains fetchAll/fetchMemberCounts/create/edit/delete/setPosition(s)/everyone/highest/premiumSubscriberRole/botRoleFor; UserManager gains createDM/deleteDM/send.
  • util/permissions.ts (new): computeGuildPermissions (owner/admin bypass, else @everyone + role bits) and compareRolePositions (position, then ID tiebreak) — checked byte-for-byte equivalent to discord.js's own algorithm.
  • tsconfig.base.json: lib moved ES2022 → ES2023 for Array#toSorted, used throughout the new manager code.

ℹ️ Nitpicks

  • GuildMemberManager.managedWith() (src/structures/GuildMember.ts) calls fetchManageable() (which already fetches the guild and both members' highest roles) and then separately re-fetches "me" and its permissions — a bit of avoidable round-tripping, not incorrect.
  • GuildPermissionsContext.roles (src/util/permissions.ts) is documented as "Every role of the guild, @everyone included", but every caller only ever passes the member's own roles plus @everyone. The algorithm only needs that subset so it's not a bug, just a doc wording that overstates what's actually passed in.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using Claude Sonnet | 𝕏

@pkg-pr-new

pkg-pr-new Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@wolfstar/plugin-api

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-api@97

@wolfstar/plugin-cache

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-cache@97

@wolfstar/plugin-gateway

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-gateway@97

@wolfstar/plugin-i18next

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-i18next@97

@wolfstar/plugin-logger

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-logger@97

@wolfstar/plugin-subcommands-advanced

pnpm add https://pkg.pr.new/wolfstar-project/plugins/@wolfstar/plugin-subcommands-advanced@97

commit: 55c73f8

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Reviewed the one new commit (2c7fa7f) since the prior pullfrog review.

  • Fixed Role#setPosition() to keep the API's actual applied position: it now captures the Role[] returned by roles.setPositions(), finds the matching entry by ID, and patches this from that (this[kPatch](updated.toJSON())) instead of blindly echoing the requested position — exactly the fix suggested in the prior review.
  • Added a regression test: mocks a clamped API response (requested position 99, Discord applies 3) and asserts both the returned instance and the cached one land on the actual applied position.

Pullfrog  | View workflow run | Using Claude Sonnet | 𝕏

@pullfrog

pullfrog Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an ANTHROPIC_API_KEY repo secret — Pullfrog routes around an exhausted subscription automatically when one is present.

Add repo secret → · Model settings → · Setup docs → · Ask in Discord →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using Claude Sonnet | 𝕏

…rity

Adds every API field and CDN URL, ClientUser with presence updates,
GuildMemberRoleManager, permission computation, member moderation and
listing, and role CRUD and positioning. Relations discord.js reads
synchronously are async fetch* methods, since the cache can be Redis.

Refs #54
@RedStar071
RedStar071 force-pushed the feat/users-members-roles branch from 020db82 to 55c73f8 Compare September 25, 2026 17:56
@pullfrog

pullfrog Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Your Claude subscription has hit its usage limit. It resets at 7:20pm (UTC). Re-trigger Pullfrog after the reset, or add an ANTHROPIC_API_KEY repo secret — Pullfrog routes around an exhausted subscription automatically when one is present.

Add repo secret → · Model settings → · Setup docs → · Ask in Discord →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using Claude Sonnet | 𝕏

@RedStar071
RedStar071 merged commit d145ace into main Sep 25, 2026
15 of 16 checks passed
@RedStar071
RedStar071 deleted the feat/users-members-roles branch September 25, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant