@@ -111,35 +111,43 @@ class ThreadMemberManager extends CachedManager {
111
111
return id ;
112
112
}
113
113
114
- async _fetchOne ( memberId , cache , force ) {
115
- if ( ! force ) {
116
- const existing = this . cache . get ( memberId ) ;
117
- if ( existing ) return existing ;
118
- }
119
-
120
- const data = await this . client . rest . get ( Routes . threadMembers ( this . thread . id , memberId ) ) ;
121
- return this . _add ( data , cache ) ;
122
- }
123
-
124
- async _fetchMany ( cache ) {
125
- const raw = await this . client . rest . get ( Routes . threadMembers ( this . thread . id ) ) ;
126
- return raw . reduce ( ( col , member ) => col . set ( member . user_id , this . _add ( member , cache ) ) , new Collection ( ) ) ;
127
- }
114
+ /**
115
+ * @typedef {BaseFetchOptions } FetchThreadMemberOptions
116
+ * @property {ThreadMemberResolvable } [member] The thread member to fetch
117
+ */
128
118
129
119
/**
130
- * @typedef {BaseFetchOptions } ThreadMemberFetchOptions
131
- * @property {UserResolvable } [member] The specific user to fetch from the thread
120
+ * @typedef {Object } FetchThreadMembersOptions
121
+ * @property {boolean } [cache] Whether to cache the fetched thread members
132
122
*/
133
123
134
124
/**
135
- * Fetches member(s) for the thread from Discord, requires access to the `GUILD_MEMBERS` gateway intent.
136
- * @param {ThreadMemberFetchOptions|boolean } [options] Additional options for this fetch, when a `boolean` is provided
137
- * all members are fetched with `options.cache` set to the boolean value
125
+ * Fetches thread member(s) from Discord. Requires the `GUILD_MEMBERS` gateway intent.
126
+ * @param {ThreadMemberResolvable|FetchThreadMemberOptions|FetchThreadMembersOptions } [options]
127
+ * Options for fetching thread member(s)
138
128
* @returns {Promise<ThreadMember|Collection<Snowflake, ThreadMember>> }
139
129
*/
140
- fetch ( { member, cache = true , force = false } = { } ) {
141
- const id = this . resolveId ( member ) ;
142
- return id ? this . _fetchOne ( id , cache , force ) : this . _fetchMany ( member ?? cache ) ;
130
+ fetch ( options ) {
131
+ if ( ! options ) return this . _fetchMany ( ) ;
132
+ const { member, cache, force } = options ;
133
+ const resolvedMember = this . resolveId ( member ?? options ) ;
134
+ if ( resolvedMember ) return this . _fetchSingle ( { member : resolvedMember , cache, force } ) ;
135
+ return this . _fetchMany ( options ) ;
136
+ }
137
+
138
+ async _fetchSingle ( { member, cache, force = false } ) {
139
+ if ( ! force ) {
140
+ const existing = this . cache . get ( member ) ;
141
+ if ( existing ) return existing ;
142
+ }
143
+
144
+ const data = await this . client . rest . get ( Routes . threadMembers ( this . thread . id , member ) ) ;
145
+ return this . _add ( data , cache ) ;
146
+ }
147
+
148
+ async _fetchMany ( options = { } ) {
149
+ const data = await this . client . rest . get ( Routes . threadMembers ( this . thread . id ) ) ;
150
+ return data . reduce ( ( col , member ) => col . set ( member . user_id , this . _add ( member , options . cache ) ) , new Collection ( ) ) ;
143
151
}
144
152
}
145
153
0 commit comments