feat(Guild): AuditLogs (#96)

* fetch audit logs

* vefificationLevel

* types
This commit is contained in:
MARCROCK22 2022-08-07 22:18:39 -04:00 committed by GitHub
parent e25c527f0e
commit 4d90686ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 473 additions and 350 deletions

View File

@ -1,441 +1,465 @@
import type { Snowflake } from '../common'; import type { AuditLogEvents, Snowflake } from '../common';
export * from './cdn'; export * from './cdn';
export function USER(userId?: Snowflake): string { export function USER(userId?: Snowflake): string {
if (!userId) { return '/users/@me'; } if (!userId) { return '/users/@me'; }
return `/users/${userId}`; return `/users/${userId}`;
} }
export function GATEWAY_BOT(): string { export function GATEWAY_BOT(): string {
return '/gateway/bot'; return '/gateway/bot';
} }
export interface GetMessagesOptions { export interface GetMessagesOptions {
limit?: number; limit?: number;
} }
export interface GetMessagesOptions { export interface GetMessagesOptions {
around?: Snowflake; around?: Snowflake;
limit?: number; limit?: number;
} }
export interface GetMessagesOptions { export interface GetMessagesOptions {
before?: Snowflake; before?: Snowflake;
limit?: number; limit?: number;
} }
export interface GetMessagesOptions { export interface GetMessagesOptions {
after?: Snowflake; after?: Snowflake;
limit?: number; limit?: number;
} }
export function CHANNEL(channelId: Snowflake): string { export function CHANNEL(channelId: Snowflake): string {
return `/channels/${channelId}`; return `/channels/${channelId}`;
} }
export function CHANNEL_INVITES(channelId: Snowflake): string { export function CHANNEL_INVITES(channelId: Snowflake): string {
return `/channels/${channelId}/invites`; return `/channels/${channelId}/invites`;
} }
export function CHANNEL_TYPING(channelId: Snowflake): string { export function CHANNEL_TYPING(channelId: Snowflake): string {
return `/channels/${channelId}/typing`; return `/channels/${channelId}/typing`;
} }
export function CHANNEL_CREATE_THREAD(channelId: Snowflake): string { export function CHANNEL_CREATE_THREAD(channelId: Snowflake): string {
return `/channels/${channelId}/threads`; return `/channels/${channelId}/threads`;
} }
export function MESSAGE_CREATE_THREAD(channelId: Snowflake, messageId: Snowflake): string { export function MESSAGE_CREATE_THREAD(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/messages/${messageId}/threads`; return `/channels/${channelId}/messages/${messageId}/threads`;
} }
/** used to send messages */ /** used to send messages */
export function CHANNEL_MESSAGES(channelId: Snowflake, options?: GetMessagesOptions): string { export function CHANNEL_MESSAGES(channelId: Snowflake, options?: GetMessagesOptions): string {
let url = `/channels/${channelId}/messages?`; let url = `/channels/${channelId}/messages?`;
if (options) { if (options) {
if (options.after) { url += `after=${options.after}`; } if (options.after) { url += `after=${options.after}`; }
if (options.before) { url += `&before=${options.before}`; } if (options.before) { url += `&before=${options.before}`; }
if (options.around) { url += `&around=${options.around}`; } if (options.around) { url += `&around=${options.around}`; }
if (options.limit) { url += `&limit=${options.limit}`; } if (options.limit) { url += `&limit=${options.limit}`; }
} }
return url; return url;
} }
/** used to edit messages */ /** used to edit messages */
export function CHANNEL_MESSAGE(channelId: Snowflake, messageId: Snowflake): string { export function CHANNEL_MESSAGE(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/messages/${messageId}`; return `/channels/${channelId}/messages/${messageId}`;
} }
/** used to kick members */ /** used to kick members */
export function GUILD_MEMBER(guildId: Snowflake, userId: Snowflake): string { export function GUILD_MEMBER(guildId: Snowflake, userId: Snowflake): string {
return `/guilds/${guildId}/members/${userId}`; return `/guilds/${guildId}/members/${userId}`;
} }
export interface ListGuildMembers { export interface ListGuildMembers {
limit?: number; limit?: number;
after?: string; after?: string;
} }
export function GUILD_MEMBERS(guildId: Snowflake, options?: ListGuildMembers) { export function GUILD_MEMBERS(guildId: Snowflake, options?: ListGuildMembers) {
let url = `/guilds/${guildId}/members?`; let url = `/guilds/${guildId}/members?`;
if (options?.limit) url += `limit=${options.limit}`; if (options?.limit) url += `limit=${options.limit}`;
if (options?.after) url += `&after=${options.after}`; if (options?.after) url += `&after=${options.after}`;
return url; return url;
} }
/** used to ban members */ /** used to ban members */
export function GUILD_BAN(guildId: Snowflake, userId: Snowflake): string { export function GUILD_BAN(guildId: Snowflake, userId: Snowflake): string {
return `/guilds/${guildId}/bans/${userId}`; return `/guilds/${guildId}/bans/${userId}`;
} }
export interface GetBans { export interface GetBans {
limit?: number; limit?: number;
before?: Snowflake; before?: Snowflake;
after?: Snowflake; after?: Snowflake;
} }
/** used to unban members */ /** used to unban members */
export function GUILD_BANS(guildId: Snowflake, options?: GetBans): string { export function GUILD_BANS(guildId: Snowflake, options?: GetBans): string {
let url = `/guilds/${guildId}/bans?`; let url = `/guilds/${guildId}/bans?`;
if (options) { if (options) {
if (options.limit) { url += `limit=${options.limit}`; } if (options.limit) { url += `limit=${options.limit}`; }
if (options.after) { url += `&after=${options.after}`; } if (options.after) { url += `&after=${options.after}`; }
if (options.before) { url += `&before=${options.before}`; } if (options.before) { url += `&before=${options.before}`; }
} }
return url; return url;
} }
export function GUILD_ROLE(guildId: Snowflake, roleId: Snowflake): string { export function GUILD_ROLE(guildId: Snowflake, roleId: Snowflake): string {
return `/guilds/${guildId}/roles/${roleId}`; return `/guilds/${guildId}/roles/${roleId}`;
} }
export function GUILD_ROLES(guildId: Snowflake): string { export function GUILD_ROLES(guildId: Snowflake): string {
return `/guilds/${guildId}/roles`; return `/guilds/${guildId}/roles`;
} }
export function USER_GUILDS(guildId?: Snowflake): string { export function USER_GUILDS(guildId?: Snowflake): string {
if (guildId) { return `/users/@me/guilds/${guildId}`; } if (guildId) { return `/users/@me/guilds/${guildId}`; }
return `/users/@me/guilds/`; return `/users/@me/guilds/`;
} }
export function USER_DM() { export function USER_DM() {
return `/users/@me/channels`; return `/users/@me/channels`;
} }
export function GUILD_EMOJIS(guildId: Snowflake): string { export function GUILD_EMOJIS(guildId: Snowflake): string {
return `/guilds/${guildId}/emojis`; return `/guilds/${guildId}/emojis`;
}
export interface GetAuditLogs {
userId?: Snowflake;
actionType?: AuditLogEvents
before?: Snowflake;
limit?: number;
}
export function GUILD_AUDIT_LOGS(guildId: Snowflake, options?: GetAuditLogs) {
let url = `/guilds/${guildId}/audit-logs?`;
if (options) {
const obj = {
user_id: options.userId,
action_type: options.actionType,
before: options.before,
limit: options.limit
};
for (const [key, value] of Object.entries(obj)) {
if (!value) continue;
url += `&${key}=${value}`
}
}
return url;
} }
export function GUILD_EMOJI(guildId: Snowflake, emojiId: Snowflake): string { export function GUILD_EMOJI(guildId: Snowflake, emojiId: Snowflake): string {
return `/guilds/${guildId}/emojis/${emojiId}`; return `/guilds/${guildId}/emojis/${emojiId}`;
} }
export interface GetInvite { export interface GetInvite {
withCounts?: boolean; withCounts?: boolean;
withExpiration?: boolean; withExpiration?: boolean;
scheduledEventId?: Snowflake; scheduledEventId?: Snowflake;
} }
export function GUILDS(guildId?: Snowflake): string { export function GUILDS(guildId?: Snowflake): string {
if (guildId) { return `/guilds/${guildId}`; } if (guildId) { return `/guilds/${guildId}`; }
return `/guilds`; return `/guilds`;
} }
export function AUTO_MODERATION_RULES(guildId: Snowflake, ruleId?: Snowflake): string { export function AUTO_MODERATION_RULES(guildId: Snowflake, ruleId?: Snowflake): string {
if (ruleId) { if (ruleId) {
return `/guilds/${guildId}/auto-moderation/rules/${ruleId}`; return `/guilds/${guildId}/auto-moderation/rules/${ruleId}`;
} }
return `/guilds/${guildId}/auto-moderation/rules`; return `/guilds/${guildId}/auto-moderation/rules`;
} }
export function INVITE(inviteCode: string, options?: GetInvite): string { export function INVITE(inviteCode: string, options?: GetInvite): string {
let url = `/invites/${inviteCode}?`; let url = `/invites/${inviteCode}?`;
if (options) { if (options) {
if (options.withCounts) { url += `with_counts=${options.withCounts}`; } if (options.withCounts) { url += `with_counts=${options.withCounts}`; }
if (options.withExpiration) { url += `&with_expiration=${options.withExpiration}`; } if (options.withExpiration) { url += `&with_expiration=${options.withExpiration}`; }
if (options.scheduledEventId) { url += `&guild_scheduled_event_id=${options.scheduledEventId}`; } if (options.scheduledEventId) { url += `&guild_scheduled_event_id=${options.scheduledEventId}`; }
} }
return url; return url;
} }
export function GUILD_INVITES(guildId: Snowflake): string { export function GUILD_INVITES(guildId: Snowflake): string {
return `/guilds/${guildId}/invites`; return `/guilds/${guildId}/invites`;
} }
export function INTERACTION_ID_TOKEN(interactionId: Snowflake, token: string): string { export function INTERACTION_ID_TOKEN(interactionId: Snowflake, token: string): string {
return `/interactions/${interactionId}/${token}/callback`; return `/interactions/${interactionId}/${token}/callback`;
} }
export function WEBHOOK_MESSAGE_ORIGINAL(webhookId: Snowflake, token: string, options?: { threadId?: bigint }): string { export function WEBHOOK_MESSAGE_ORIGINAL(webhookId: Snowflake, token: string, options?: { threadId?: bigint }): string {
let url = `/webhooks/${webhookId}/${token}/messages/@original?`; let url = `/webhooks/${webhookId}/${token}/messages/@original?`;
if (options) { if (options) {
if (options.threadId) { url += `thread_id=${options.threadId}`; } if (options.threadId) { url += `thread_id=${options.threadId}`; }
} }
return url; return url;
} }
export function WEBHOOK_MESSAGE( export function WEBHOOK_MESSAGE(
webhookId: Snowflake, webhookId: Snowflake,
token: string, token: string,
messageId: Snowflake, messageId: Snowflake,
options?: { threadId?: Snowflake }, options?: { threadId?: Snowflake },
): string { ): string {
let url = `/webhooks/${webhookId}/${token}/messages/${messageId}?`; let url = `/webhooks/${webhookId}/${token}/messages/${messageId}?`;
if (options) { if (options) {
if (options.threadId) { url += `thread_id=${options.threadId}`; } if (options.threadId) { url += `thread_id=${options.threadId}`; }
} }
return url; return url;
} }
export function WEBHOOK_TOKEN(webhookId: Snowflake, token?: string): string { export function WEBHOOK_TOKEN(webhookId: Snowflake, token?: string): string {
if (!token) { return `/webhooks/${webhookId}`; } if (!token) { return `/webhooks/${webhookId}`; }
return `/webhooks/${webhookId}/${token}`; return `/webhooks/${webhookId}/${token}`;
} }
export interface WebhookOptions { export interface WebhookOptions {
wait?: boolean; wait?: boolean;
threadId?: Snowflake; threadId?: Snowflake;
} }
export function WEBHOOK(webhookId: Snowflake, token: string, options?: WebhookOptions): string { export function WEBHOOK(webhookId: Snowflake, token: string, options?: WebhookOptions): string {
let url = `/webhooks/${webhookId}/${token}`; let url = `/webhooks/${webhookId}/${token}`;
if (options?.wait) { url += `?wait=${options.wait}`; } if (options?.wait) { url += `?wait=${options.wait}`; }
if (options?.threadId) { url += `?thread_id=${options.threadId}`; } if (options?.threadId) { url += `?thread_id=${options.threadId}`; }
if (options?.wait && options.threadId) { url += `?wait=${options.wait}&thread_id=${options.threadId}`; } if (options?.wait && options.threadId) { url += `?wait=${options.wait}&thread_id=${options.threadId}`; }
return url; return url;
} }
export function USER_NICK(guildId: Snowflake): string { export function USER_NICK(guildId: Snowflake): string {
return `/guilds/${guildId}/members/@me`; return `/guilds/${guildId}/members/@me`;
} }
/** /**
* @link https://discord.com/developers/docs/resources/guild#get-guild-prune-count * @link https://discord.com/developers/docs/resources/guild#get-guild-prune-count
*/ */
export interface GetGuildPruneCountQuery { export interface GetGuildPruneCountQuery {
days?: number; days?: number;
includeRoles?: Snowflake | Snowflake[]; includeRoles?: Snowflake | Snowflake[];
} }
export function GUILD_PRUNE(guildId: Snowflake, options?: GetGuildPruneCountQuery): string { export function GUILD_PRUNE(guildId: Snowflake, options?: GetGuildPruneCountQuery): string {
let url = `/guilds/${guildId}/prune?`; let url = `/guilds/${guildId}/prune?`;
if (options?.days) { url += `days=${options.days}`; } if (options?.days) { url += `days=${options.days}`; }
if (options?.includeRoles) { url += `&include_roles=${options.includeRoles}`; } if (options?.includeRoles) { url += `&include_roles=${options.includeRoles}`; }
return url; return url;
} }
export function CHANNEL_PIN(channelId: Snowflake, messageId: Snowflake): string { export function CHANNEL_PIN(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/pins/${messageId}`; return `/channels/${channelId}/pins/${messageId}`;
} }
export function CHANNEL_PINS(channelId: Snowflake): string { export function CHANNEL_PINS(channelId: Snowflake): string {
return `/channels/${channelId}/pins`; return `/channels/${channelId}/pins`;
} }
export function CHANNEL_MESSAGE_REACTION_ME(channelId: Snowflake, messageId: Snowflake, emoji: string): string { export function CHANNEL_MESSAGE_REACTION_ME(channelId: Snowflake, messageId: Snowflake, emoji: string): string {
return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/@me`; return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/@me`;
} }
export function CHANNEL_MESSAGE_REACTION_USER( export function CHANNEL_MESSAGE_REACTION_USER(
channelId: Snowflake, channelId: Snowflake,
messageId: Snowflake, messageId: Snowflake,
emoji: string, emoji: string,
userId: Snowflake, userId: Snowflake,
) { ) {
return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/${userId}`; return `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}/${userId}`;
} }
export function CHANNEL_MESSAGE_REACTIONS(channelId: Snowflake, messageId: Snowflake) { export function CHANNEL_MESSAGE_REACTIONS(channelId: Snowflake, messageId: Snowflake) {
return `/channels/${channelId}/messages/${messageId}/reactions`; return `/channels/${channelId}/messages/${messageId}/reactions`;
} }
/** /**
* @link https://discord.com/developers/docs/resources/channel#get-reactions-query-string-params * @link https://discord.com/developers/docs/resources/channel#get-reactions-query-string-params
*/ */
export interface GetReactions { export interface GetReactions {
after?: string; after?: string;
limit?: number; limit?: number;
} }
export function CHANNEL_MESSAGE_REACTION( export function CHANNEL_MESSAGE_REACTION(
channelId: Snowflake, channelId: Snowflake,
messageId: Snowflake, messageId: Snowflake,
emoji: string, emoji: string,
options?: GetReactions, options?: GetReactions,
): string { ): string {
let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`; let url = `/channels/${channelId}/messages/${messageId}/reactions/${encodeURIComponent(emoji)}?`;
if (options?.after) { url += `after=${options.after}`; } if (options?.after) { url += `after=${options.after}`; }
if (options?.limit) { url += `&limit=${options.limit}`; } if (options?.limit) { url += `&limit=${options.limit}`; }
return url; return url;
} }
export function CHANNEL_MESSAGE_CROSSPOST(channelId: Snowflake, messageId: Snowflake): string { export function CHANNEL_MESSAGE_CROSSPOST(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/messages/${messageId}/crosspost`; return `/channels/${channelId}/messages/${messageId}/crosspost`;
} }
export function GUILD_MEMBER_ROLE(guildId: Snowflake, memberId: Snowflake, roleId: Snowflake): string { export function GUILD_MEMBER_ROLE(guildId: Snowflake, memberId: Snowflake, roleId: Snowflake): string {
return `/guilds/${guildId}/members/${memberId}/roles/${roleId}`; return `/guilds/${guildId}/members/${memberId}/roles/${roleId}`;
} }
export function CHANNEL_WEBHOOKS(channelId: Snowflake): string { export function CHANNEL_WEBHOOKS(channelId: Snowflake): string {
return `/channels/${channelId}/webhooks`; return `/channels/${channelId}/webhooks`;
} }
export function THREAD_START_PUBLIC(channelId: Snowflake, messageId: Snowflake): string { export function THREAD_START_PUBLIC(channelId: Snowflake, messageId: Snowflake): string {
return `/channels/${channelId}/messages/${messageId}/threads`; return `/channels/${channelId}/messages/${messageId}/threads`;
} }
export function THREAD_START_PRIVATE(channelId: Snowflake): string { export function THREAD_START_PRIVATE(channelId: Snowflake): string {
return `/channels/${channelId}/threads`; return `/channels/${channelId}/threads`;
} }
export function THREAD_ACTIVE(guildId: Snowflake): string { export function THREAD_ACTIVE(guildId: Snowflake): string {
return `/guilds/${guildId}/threads/active`; return `/guilds/${guildId}/threads/active`;
} }
export interface ListArchivedThreads { export interface ListArchivedThreads {
before?: number; before?: number;
limit?: number; limit?: number;
} }
export function THREAD_ME(channelId: Snowflake): string { export function THREAD_ME(channelId: Snowflake): string {
return `/channels/${channelId}/thread-members/@me`; return `/channels/${channelId}/thread-members/@me`;
} }
export function THREAD_MEMBERS(channelId: Snowflake): string { export function THREAD_MEMBERS(channelId: Snowflake): string {
return `/channels/${channelId}/thread-members`; return `/channels/${channelId}/thread-members`;
} }
export function THREAD_USER(channelId: Snowflake, userId: Snowflake): string { export function THREAD_USER(channelId: Snowflake, userId: Snowflake): string {
return `/channels/${channelId}/thread-members/${userId}`; return `/channels/${channelId}/thread-members/${userId}`;
} }
export function THREAD_ARCHIVED(channelId: Snowflake): string { export function THREAD_ARCHIVED(channelId: Snowflake): string {
return `/channels/${channelId}/threads/archived`; return `/channels/${channelId}/threads/archived`;
} }
export function THREAD_ARCHIVED_PUBLIC(channelId: Snowflake, options?: ListArchivedThreads): string { export function THREAD_ARCHIVED_PUBLIC(channelId: Snowflake, options?: ListArchivedThreads): string {
let url = `/channels/${channelId}/threads/archived/public?`; let url = `/channels/${channelId}/threads/archived/public?`;
if (options) { if (options) {
if (options.before) { url += `before=${new Date(options.before).toISOString()}`; } if (options.before) { url += `before=${new Date(options.before).toISOString()}`; }
if (options.limit) { url += `&limit=${options.limit}`; } if (options.limit) { url += `&limit=${options.limit}`; }
} }
return url; return url;
} }
export function THREAD_ARCHIVED_PRIVATE(channelId: Snowflake, options?: ListArchivedThreads): string { export function THREAD_ARCHIVED_PRIVATE(channelId: Snowflake, options?: ListArchivedThreads): string {
let url = `/channels/${channelId}/threads/archived/private?`; let url = `/channels/${channelId}/threads/archived/private?`;
if (options) { if (options) {
if (options.before) { url += `before=${new Date(options.before).toISOString()}`; } if (options.before) { url += `before=${new Date(options.before).toISOString()}`; }
if (options.limit) { url += `&limit=${options.limit}`; } if (options.limit) { url += `&limit=${options.limit}`; }
} }
return url; return url;
} }
export function THREAD_ARCHIVED_PRIVATE_JOINED(channelId: Snowflake, options?: ListArchivedThreads): string { export function THREAD_ARCHIVED_PRIVATE_JOINED(channelId: Snowflake, options?: ListArchivedThreads): string {
let url = `/channels/${channelId}/users/@me/threads/archived/private?`; let url = `/channels/${channelId}/users/@me/threads/archived/private?`;
if (options) { if (options) {
if (options.before) { url += `before=${new Date(options.before).toISOString()}`; } if (options.before) { url += `before=${new Date(options.before).toISOString()}`; }
if (options.limit) { url += `&limit=${options.limit}`; } if (options.limit) { url += `&limit=${options.limit}`; }
} }
return url; return url;
} }
export function FORUM_START(channelId: Snowflake): string { export function FORUM_START(channelId: Snowflake): string {
return `/channels/${channelId}/threads?has_message=true`; return `/channels/${channelId}/threads?has_message=true`;
} }
export function STAGE_INSTANCES(): string { export function STAGE_INSTANCES(): string {
return `/stage-instances`; return `/stage-instances`;
} }
export function STAGE_INSTANCE(channelId: Snowflake): string { export function STAGE_INSTANCE(channelId: Snowflake): string {
return `/stage-instances/${channelId}`; return `/stage-instances/${channelId}`;
} }
export function APPLICATION_COMMANDS(appId: Snowflake, commandId?: Snowflake): string { export function APPLICATION_COMMANDS(appId: Snowflake, commandId?: Snowflake): string {
if (commandId) { return `/applications/${appId}/commands/${commandId}`; } if (commandId) { return `/applications/${appId}/commands/${commandId}`; }
return `/applications/${appId}/commands`; return `/applications/${appId}/commands`;
} }
export function GUILD_APPLICATION_COMMANDS(appId: Snowflake, guildId: Snowflake, commandId?: Snowflake): string { export function GUILD_APPLICATION_COMMANDS(appId: Snowflake, guildId: Snowflake, commandId?: Snowflake): string {
if (commandId) { return `/applications/${appId}/guilds/${guildId}/commands/${commandId}`; } if (commandId) { return `/applications/${appId}/guilds/${guildId}/commands/${commandId}`; }
return `/applications/${appId}/guilds/${guildId}/commands`; return `/applications/${appId}/guilds/${guildId}/commands`;
} }
export function GUILD_APPLICATION_COMMANDS_PERMISSIONS( export function GUILD_APPLICATION_COMMANDS_PERMISSIONS(
appId: Snowflake, appId: Snowflake,
guildId: Snowflake, guildId: Snowflake,
commandId?: Snowflake, commandId?: Snowflake,
): string { ): string {
if (commandId) { return `/applications/${appId}/guilds/${guildId}/commands/${commandId}/permissions`; } if (commandId) { return `/applications/${appId}/guilds/${guildId}/commands/${commandId}/permissions`; }
return `/applications/${appId}/guilds/${guildId}/commands/permissions`; return `/applications/${appId}/guilds/${guildId}/commands/permissions`;
} }
export function APPLICATION_COMMANDS_LOCALIZATIONS( export function APPLICATION_COMMANDS_LOCALIZATIONS(
appId: Snowflake, appId: Snowflake,
commandId: Snowflake, commandId: Snowflake,
withLocalizations?: boolean, withLocalizations?: boolean,
): string { ): string {
let url = `/applications/${appId}/commands/${commandId}?`; let url = `/applications/${appId}/commands/${commandId}?`;
if (withLocalizations !== undefined) { if (withLocalizations !== undefined) {
url += `withLocalizations=${withLocalizations}`; url += `withLocalizations=${withLocalizations}`;
} }
return url; return url;
} }
export function GUILD_APPLICATION_COMMANDS_LOCALIZATIONS( export function GUILD_APPLICATION_COMMANDS_LOCALIZATIONS(
appId: Snowflake, appId: Snowflake,
guildId: Snowflake, guildId: Snowflake,
commandId: Snowflake, commandId: Snowflake,
withLocalizations?: boolean, withLocalizations?: boolean,
): string { ): string {
let url = `/applications/${appId}/guilds/${guildId}/commands/${commandId}?`; let url = `/applications/${appId}/guilds/${guildId}/commands/${commandId}?`;
if (withLocalizations !== undefined) { if (withLocalizations !== undefined) {
url += `with_localizations=${withLocalizations}`; url += `with_localizations=${withLocalizations}`;
} }
return url; return url;
} }
export function STICKER(id: Snowflake): string { export function STICKER(id: Snowflake): string {
return `stickers/${id}`; return `stickers/${id}`;
} }
export function STICKER_PACKS(): string { export function STICKER_PACKS(): string {
return `stickers-packs`; return `stickers-packs`;
} }
export function GUILD_STICKERS(guildId: Snowflake, stickerId?: Snowflake): string { export function GUILD_STICKERS(guildId: Snowflake, stickerId?: Snowflake): string {
if (stickerId) { return `/guilds/${guildId}/stickers/${stickerId}`; } if (stickerId) { return `/guilds/${guildId}/stickers/${stickerId}`; }
return `/guilds/${guildId}/stickers`; return `/guilds/${guildId}/stickers`;
} }
/** /**
@ -443,7 +467,7 @@ export function GUILD_STICKERS(guildId: Snowflake, stickerId?: Snowflake): strin
* @link https://discord.com/developers/docs/resources/guild#get-guild-widget-settings * @link https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
*/ */
export interface GetWidget { export interface GetWidget {
get: 'json' | 'image' | 'settings'; get: 'json' | 'image' | 'settings';
} }
/** /**
@ -451,19 +475,19 @@ export interface GetWidget {
* @link https://discord.com/developers/docs/resources/guild#get-guild-widget-settings * @link https://discord.com/developers/docs/resources/guild#get-guild-widget-settings
*/ */
export function GUILD_WIDGET(guildId: Snowflake, options: GetWidget = { get: 'settings' }): string { export function GUILD_WIDGET(guildId: Snowflake, options: GetWidget = { get: 'settings' }): string {
let url = `/guilds/${guildId}/widget`; let url = `/guilds/${guildId}/widget`;
if (options.get === 'json') { if (options.get === 'json') {
url += '.json'; url += '.json';
} else if (options.get === 'image') { } else if (options.get === 'image') {
url += '.png'; url += '.png';
} }
return url; return url;
} }
/** @link https://discord.com/developers/docs/resources/guild#get-guild-voice-regions */ /** @link https://discord.com/developers/docs/resources/guild#get-guild-voice-regions */
export function GUILD_VOICE_REGIONS(guildId: Snowflake): string { export function GUILD_VOICE_REGIONS(guildId: Snowflake): string {
return `/guilds/${guildId}/regions`; return `/guilds/${guildId}/regions`;
} }
/** /**
@ -472,7 +496,7 @@ export function GUILD_VOICE_REGIONS(guildId: Snowflake): string {
* @returns Get vanity URL * @returns Get vanity URL
*/ */
export function GUILD_VANITY(guildId: Snowflake): string { export function GUILD_VANITY(guildId: Snowflake): string {
return `/guilds/${guildId}/vanity-url`; return `/guilds/${guildId}/vanity-url`;
} }
/** /**
@ -481,7 +505,7 @@ export function GUILD_VANITY(guildId: Snowflake): string {
* @returns Get guild preview url * @returns Get guild preview url
*/ */
export function GUILD_PREVIEW(guildId: Snowflake): string { export function GUILD_PREVIEW(guildId: Snowflake): string {
return `/guilds/${guildId}/preview`; return `/guilds/${guildId}/preview`;
} }
/** /**
@ -490,5 +514,5 @@ export function GUILD_PREVIEW(guildId: Snowflake): string {
* @returns Get guild channels url. * @returns Get guild channels url.
*/ */
export function GUILD_CHANNELS(guildId: Snowflake): string { export function GUILD_CHANNELS(guildId: Snowflake): string {
return `/guilds/${guildId}/channels`; return `/guilds/${guildId}/channels`;
} }

View File

@ -295,7 +295,7 @@ export interface DiscordTeamMember {
team_id: string; team_id: string;
/** The avatar, discriminator, id, and username of the user */ /** The avatar, discriminator, id, and username of the user */
user: Partial<DiscordUser> & user: Partial<DiscordUser> &
Pick<DiscordUser, 'avatar' | 'discriminator' | 'id' | 'username'>; Pick<DiscordUser, 'avatar' | 'discriminator' | 'id' | 'username'>;
} }
/** https://discord.com/developers/docs/topics/gateway#webhooks-update-webhook-update-event-fields */ /** https://discord.com/developers/docs/topics/gateway#webhooks-update-webhook-update-event-fields */
@ -1149,30 +1149,30 @@ export interface DiscordActionRow {
type: 1; type: 1;
/** The components in this row */ /** The components in this row */
components: components:
| [ | [
| DiscordSelectMenuComponent | DiscordSelectMenuComponent
| DiscordButtonComponent | DiscordButtonComponent
| DiscordInputTextComponent | DiscordInputTextComponent
] ]
| [DiscordButtonComponent, DiscordButtonComponent] | [DiscordButtonComponent, DiscordButtonComponent]
| [ | [
DiscordButtonComponent, DiscordButtonComponent,
DiscordButtonComponent, DiscordButtonComponent,
DiscordButtonComponent DiscordButtonComponent
] ]
| [ | [
DiscordButtonComponent, DiscordButtonComponent,
DiscordButtonComponent, DiscordButtonComponent,
DiscordButtonComponent, DiscordButtonComponent,
DiscordButtonComponent DiscordButtonComponent
] ]
| [ | [
DiscordButtonComponent, DiscordButtonComponent,
DiscordButtonComponent, DiscordButtonComponent,
DiscordButtonComponent, DiscordButtonComponent,
DiscordButtonComponent, DiscordButtonComponent,
DiscordButtonComponent DiscordButtonComponent
]; ];
} }
export interface DiscordSelectMenuComponent { export interface DiscordSelectMenuComponent {
@ -1311,10 +1311,10 @@ export interface DiscordInteraction {
data?: DiscordInteractionData; data?: DiscordInteractionData;
/** The guild's preferred locale, if invoked in a guild */ /** The guild's preferred locale, if invoked in a guild */
guild_locale?: string; guild_locale?: string;
/** Bitwise set of permissions the app or bot has within the channel the interaction was sent from */ /** Bitwise set of permissions the app or bot has within the channel the interaction was sent from */
app_permissions?: string; app_permissions?: string;
/** Selected language of the invoking user */ /** Selected language of the invoking user */
locale?: string; locale?: string;
} }
/** https://discord.com/developers/docs/resources/guild#guild-member-object */ /** https://discord.com/developers/docs/resources/guild#guild-member-object */
@ -1374,12 +1374,12 @@ export type DiscordInteractionDataOption = {
type: ApplicationCommandOptionTypes; type: ApplicationCommandOptionTypes;
/** Value of the option resulting from user input */ /** Value of the option resulting from user input */
value?: value?:
| string | string
| boolean | boolean
| number | number
| DiscordMember | DiscordMember
| DiscordChannel | DiscordChannel
| DiscordRole; | DiscordRole;
/** Present if this option is a group or subcommand */ /** Present if this option is a group or subcommand */
options?: DiscordInteractionDataOption[]; options?: DiscordInteractionDataOption[];
/** `true` if this option is the currently focused option for autocomplete */ /** `true` if this option is the currently focused option for autocomplete */
@ -1439,7 +1439,12 @@ export interface DiscordAuditLog {
/** List of audit log entries, sorted from most to least recent */ /** List of audit log entries, sorted from most to least recent */
audit_log_entries: DiscordAuditLogEntry[]; audit_log_entries: DiscordAuditLogEntry[];
/** List of partial integration objects */ /** List of partial integration objects */
integrations: Partial<DiscordIntegration>[]; integrations: ({
type: 'youtube' | 'twitch' | 'discord';
id: string;
name: string;
account: DiscordIntegrationAccount;
} & Partial<DiscordIntegration>)[];
/** /**
* List of threads found in the audit log. * List of threads found in the audit log.
* Threads referenced in `THREAD_CREATE` and `THREAD_UPDATE` events are included in the threads map since archived threads might not be kept in memory by clients. * Threads referenced in `THREAD_CREATE` and `THREAD_UPDATE` events are included in the threads map since archived threads might not be kept in memory by clients.
@ -1576,97 +1581,97 @@ export interface DiscordAuditLogEntry {
/** https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-structure */ /** https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-structure */
export type DiscordAuditLogChange = export type DiscordAuditLogChange =
| { | {
new_value: string; new_value: string;
old_value: string; old_value: string;
key: key:
| 'name' | 'name'
| 'description' | 'description'
| 'discovery_splash_hash' | 'discovery_splash_hash'
| 'banner_hash' | 'banner_hash'
| 'preferred_locale' | 'preferred_locale'
| 'rules_channel_id' | 'rules_channel_id'
| 'public_updates_channel_id' | 'public_updates_channel_id'
| 'icon_hash' | 'icon_hash'
| 'image_hash' | 'image_hash'
| 'splash_hash' | 'splash_hash'
| 'owner_id' | 'owner_id'
| 'region' | 'region'
| 'afk_channel_id' | 'afk_channel_id'
| 'vanity_url_code' | 'vanity_url_code'
| 'widget_channel_id' | 'widget_channel_id'
| 'system_channel_id' | 'system_channel_id'
| 'topic' | 'topic'
| 'application_id' | 'application_id'
| 'permissions' | 'permissions'
| 'allow' | 'allow'
| 'deny' | 'deny'
| 'code' | 'code'
| 'channel_id' | 'channel_id'
| 'inviter_id' | 'inviter_id'
| 'nick' | 'nick'
| 'avatar_hash' | 'avatar_hash'
| 'id' | 'id'
| 'location' | 'location'
| 'command_id'; | 'command_id';
} }
| { | {
new_value: number; new_value: number;
old_value: number; old_value: number;
key: key:
| 'afk_timeout' | 'afk_timeout'
| 'mfa_level' | 'mfa_level'
| 'verification_level' | 'verification_level'
| 'explicit_content_filter' | 'explicit_content_filter'
| 'default_message_notifications' | 'default_message_notifications'
| 'prune_delete_days' | 'prune_delete_days'
| 'position' | 'position'
| 'bitrate' | 'bitrate'
| 'rate_limit_per_user' | 'rate_limit_per_user'
| 'color' | 'color'
| 'max_uses' | 'max_uses'
| 'uses' | 'uses'
| 'max_age' | 'max_age'
| 'expire_behavior' | 'expire_behavior'
| 'expire_grace_period' | 'expire_grace_period'
| 'user_limit' | 'user_limit'
| 'privacy_level' | 'privacy_level'
| 'auto_archive_duration' | 'auto_archive_duration'
| 'default_auto_archive_duration' | 'default_auto_archive_duration'
| 'entity_type' | 'entity_type'
| 'status' | 'status'
| 'communication_disabled_until'; | 'communication_disabled_until';
} }
| { | {
new_value: Partial<DiscordRole>[]; new_value: Partial<DiscordRole>[];
old_value?: Partial<DiscordRole>[]; old_value?: Partial<DiscordRole>[];
key: '$add' | '$remove'; key: '$add' | '$remove';
} }
| { | {
new_value: boolean; new_value: boolean;
old_value: boolean; old_value: boolean;
key: key:
| 'widget_enabled' | 'widget_enabled'
| 'nsfw' | 'nsfw'
| 'hoist' | 'hoist'
| 'mentionable' | 'mentionable'
| 'temporary' | 'temporary'
| 'deaf' | 'deaf'
| 'mute' | 'mute'
| 'enable_emoticons' | 'enable_emoticons'
| 'archived' | 'archived'
| 'locked' | 'locked'
| 'invitable'; | 'invitable';
} }
| { | {
new_value: DiscordOverwrite[]; new_value: DiscordOverwrite[];
old_value: DiscordOverwrite[]; old_value: DiscordOverwrite[];
key: 'permission_overwrites'; key: 'permission_overwrites';
} }
| { | {
new_value: string | number; new_value: string | number;
old_value: string | number; old_value: string | number;
key: 'type'; key: 'type';
}; };
/** https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info */ /** https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info */
export interface DiscordOptionalAuditEntryInfo { export interface DiscordOptionalAuditEntryInfo {
@ -2127,7 +2132,7 @@ export interface DiscordGuildBanAddRemove {
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove */ /** https://discord.com/developers/docs/topics/gateway#message-reaction-remove */
export interface DiscordMessageReactionRemove export interface DiscordMessageReactionRemove
extends Omit<DiscordMessageReactionAdd, 'member'> {} extends Omit<DiscordMessageReactionAdd, 'member'> { }
/** https://discord.com/developers/docs/topics/gateway#message-reaction-add */ /** https://discord.com/developers/docs/topics/gateway#message-reaction-add */
export interface DiscordMessageReactionAdd { export interface DiscordMessageReactionAdd {
@ -2203,12 +2208,12 @@ export interface DiscordReady {
shard?: [number, number]; shard?: [number, number];
/** Contains id and flags */ /** Contains id and flags */
application: Partial<DiscordApplication> & application: Partial<DiscordApplication> &
Pick<DiscordApplication, 'id' | 'flags'>; Pick<DiscordApplication, 'id' | 'flags'>;
} }
/** https://discord.com/developers/docs/resources/guild#unavailable-guild-object */ /** https://discord.com/developers/docs/resources/guild#unavailable-guild-object */
export interface DiscordUnavailableGuild export interface DiscordUnavailableGuild
extends Pick<DiscordGuild, 'id' | 'unavailable'> {} extends Pick<DiscordGuild, 'id' | 'unavailable'> { }
/** https://discord.com/developers/docs/topics/gateway#message-delete-bulk */ /** https://discord.com/developers/docs/topics/gateway#message-delete-bulk */
export interface DiscordMessageDeleteBulk { export interface DiscordMessageDeleteBulk {
@ -2380,9 +2385,9 @@ export interface DiscordGuildMemberUpdate {
/** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-all */ /** https://discord.com/developers/docs/topics/gateway#message-reaction-remove-all */
export interface DiscordMessageReactionRemoveAll export interface DiscordMessageReactionRemoveAll
extends Pick< extends Pick<
DiscordMessageReactionAdd, DiscordMessageReactionAdd,
'channel_id' | 'message_id' | 'guild_id' 'channel_id' | 'message_id' | 'guild_id'
> {} > { }
// TODO: add docs link // TODO: add docs link
export interface DiscordValidateDiscoverySearchTerm { export interface DiscordValidateDiscoverySearchTerm {

View File

@ -25,7 +25,12 @@ import {
VideoQualityModes, VideoQualityModes,
GetBans, GetBans,
GetInvite, GetInvite,
ListGuildMembers, ListGuildMembers,
GetAuditLogs,
GUILD_AUDIT_LOGS,
DiscordAuditLog,
AuditLogEvents,
DiscordAuditLogChange,
} from '@biscuitland/api-types'; } from '@biscuitland/api-types';
import type { ImageFormat, ImageSize } from '../utils/util'; import type { ImageFormat, ImageSize } from '../utils/util';
import { GuildFeatures, PremiumTiers } from '@biscuitland/api-types'; import { GuildFeatures, PremiumTiers } from '@biscuitland/api-types';
@ -46,7 +51,7 @@ import {
GUILD_PRUNE, GUILD_PRUNE,
GUILD_INVITES, GUILD_INVITES,
GUILD_MEMBER, GUILD_MEMBER,
GUILD_MEMBERS, GUILD_MEMBERS,
GUILD_MEMBER_ROLE, GUILD_MEMBER_ROLE,
GUILD_ROLE, GUILD_ROLE,
GUILD_ROLES, GUILD_ROLES,
@ -69,6 +74,9 @@ import { Widget } from './widget';
import { Sticker } from './sticker'; import { Sticker } from './sticker';
import { WelcomeScreen } from './welcome'; import { WelcomeScreen } from './welcome';
import { AutoModerationRule } from './automod'; import { AutoModerationRule } from './automod';
import { Webhook } from './webhook';
import { ScheduledEvent } from './scheduled-events';
import Integration from './integration';
/** BaseGuild */ /** BaseGuild */
/** /**
@ -286,11 +294,11 @@ export class GuildPreview implements Model {
? Util.iconHashToBigInt(data.icon) ? Util.iconHashToBigInt(data.icon)
: undefined; : undefined;
this.splashHash = data.splash this.splashHash = data.splash
? Util.iconHashToBigInt(data.splash) ? Util.iconHashToBigInt(data.splash)
: undefined; : undefined;
this.discoverySplashHash = data.discovery_splash this.discoverySplashHash = data.discovery_splash
? Util.iconHashToBigInt(data.discovery_splash) ? Util.iconHashToBigInt(data.discovery_splash)
: undefined; : undefined;
@ -298,7 +306,7 @@ export class GuildPreview implements Model {
x => new GuildEmoji(this.session, x, this.id) x => new GuildEmoji(this.session, x, this.id)
); );
this.features = data.features; this.features = data.features;
this.approximateMemberCount = data.approximate_member_count; this.approximateMemberCount = data.approximate_member_count;
this.approximatePresenceCount = data.approximate_presence_count; this.approximatePresenceCount = data.approximate_presence_count;
this.stickers = data.stickers.map(x => new Sticker(this.session, x)); this.stickers = data.stickers.map(x => new Sticker(this.session, x));
@ -435,9 +443,9 @@ export interface GuildCreateOptionsChannel {
id?: Snowflake; id?: Snowflake;
parentId?: Snowflake; parentId?: Snowflake;
type?: type?:
| ChannelTypes.GuildText | ChannelTypes.GuildText
| ChannelTypes.GuildVoice | ChannelTypes.GuildVoice
| ChannelTypes.GuildCategory; | ChannelTypes.GuildCategory;
name: string; name: string;
topic?: string | null; topic?: string | null;
nsfw?: boolean; nsfw?: boolean;
@ -482,6 +490,38 @@ export interface GuildEditOptions extends Partial<GuildCreateOptions> {
premiumProgressBarEnabled?: boolean; premiumProgressBarEnabled?: boolean;
} }
export interface AuditLogResult {
auditLogEntries: {
targetId: string | null;
changes: {
key: DiscordAuditLogChange['key'];
oldValue: DiscordOverwrite[] | Role[] | string | number | boolean | null;
newValue: DiscordOverwrite[] | Role[] | string | number | boolean | null;
}[] | undefined;
userId: string | null;
id: string;
actionType: AuditLogEvents;
options: {
deleteMemberDays: string;
membersRemoved: string;
channelId: string;
messageId: string;
count: string;
id: string;
type: string;
roleName: string;
applicationId: string;
} | null;
reason: string | undefined;
}[];
autoModerationRules: AutoModerationRule[] | undefined;
guildScheduledEvents: ScheduledEvent[] | undefined;
integrations: Integration[];
threads: ThreadChannel[];
users: User[];
webhooks: Webhook[];
}
/** /**
* Represents a guild. * Represents a guild.
* @see {@link BaseGuild}. * @see {@link BaseGuild}.
@ -502,7 +542,7 @@ export class Guild extends BaseGuild implements Model {
this.widgetChannelId = data.widget_channel_id this.widgetChannelId = data.widget_channel_id
? data.widget_channel_id ? data.widget_channel_id
: undefined; : undefined;
this.vefificationLevel = data.verification_level; this.verificationLevel = data.verification_level;
this.defaultMessageNotificationLevel = this.defaultMessageNotificationLevel =
data.default_message_notifications; data.default_message_notifications;
this.explicitContentFilterLevel = data.explicit_content_filter; this.explicitContentFilterLevel = data.explicit_content_filter;
@ -558,7 +598,7 @@ export class Guild extends BaseGuild implements Model {
* @see {@link VerificationLevels} * @see {@link VerificationLevels}
* @link https://discord.com/developers/docs/resources/guild#guild-object-verification-level * @link https://discord.com/developers/docs/resources/guild#guild-object-verification-level
*/ */
vefificationLevel: VerificationLevels; verificationLevel: VerificationLevels;
/** /**
* The default message notification level. * The default message notification level.
@ -872,9 +912,9 @@ export class Guild extends BaseGuild implements Model {
GUILD_BAN(this.id, memberId), GUILD_BAN(this.id, memberId),
options options
? { ? {
delete_message_days: options.deleteMessageDays, delete_message_days: options.deleteMessageDays,
reason: options.reason, reason: options.reason,
} }
: {} : {}
); );
} }
@ -1127,7 +1167,7 @@ export class Guild extends BaseGuild implements Model {
* @returns * @returns
*/ */
fetchAutoModerationRules(ruleId?: Snowflake): Promise<AutoModerationRule | AutoModerationRule[]> { fetchAutoModerationRules(ruleId?: Snowflake): Promise<AutoModerationRule | AutoModerationRule[]> {
return AutoModerationRule.prototype.getRules.call({session: this.session, guildId: this.id}, ruleId); return AutoModerationRule.prototype.getRules.call({ session: this.session, guildId: this.id }, ruleId);
} }
/** /**
@ -1239,21 +1279,75 @@ export class Guild extends BaseGuild implements Model {
return channels.map(channel => ChannelFactory.fromGuildChannel(this.session, channel)); return channels.map(channel => ChannelFactory.fromGuildChannel(this.session, channel));
} }
/** fetches a member */ async fetchAuditLogs(options?: GetAuditLogs): Promise<AuditLogResult> {
async fetchMember(memberId: Snowflake): Promise<Member> { const auditLog = await this.session.rest.get<DiscordAuditLog>(GUILD_AUDIT_LOGS(this.id, options));
const member = await this.session.rest.get<DiscordMemberWithUser>( return {
GUILD_MEMBER(this.id, memberId) auditLogEntries: auditLog.audit_log_entries.map(x => ({
); targetId: x.target_id,
changes: x.changes?.map(j => ({
key: j.key,
oldValue: j.old_value
? j.key === 'permission_overwrites'
? (j.old_value as DiscordOverwrite[])
: ['$add', '$remove'].includes(j.key)
? (j.old_value as DiscordRole[]).map(j => new Role(this.session, { ...j, permissions: j.permissions || '0' }, this.id))
: j.old_value as string | number | boolean
: null,
newValue: j.new_value
? j.key === 'permission_overwrites'
? (j.new_value as DiscordOverwrite[])
: ['$add', '$remove'].includes(j.key)
? (j.new_value as DiscordRole[]).map(j => new Role(this.session, { ...j, permissions: j.permissions || '0' }, this.id))
: j.new_value as string | number | boolean
: null,
})),
userId: x.user_id,
id: x.id,
actionType: x.action_type,
options: x.options ? {
deleteMemberDays: x.options.delete_member_days,
membersRemoved: x.options.members_removed,
channelId: x.options.channel_id,
messageId: x.options.message_id,
count: x.options.count,
id: x.options.id,
type: x.options.type,
roleName: x.options.role_name,
applicationId: x.options.application_id
} : null,
reason: x.reason,
})),
autoModerationRules: auditLog.auto_moderation_rules?.map(x => new AutoModerationRule(this.session, x)),
guildScheduledEvents: auditLog.guild_scheduled_events?.map(x => new ScheduledEvent(this.session, x)),
integrations: auditLog.integrations.map(x => new Integration(this.session, {
guild_id: this.id,
...x,
})),
threads: auditLog.threads.map(x => ChannelFactory.fromGuildChannel(this.session, x) as ThreadChannel),
users: auditLog.users.map(x => new User(this.session, x)),
webhooks: auditLog.webhooks.map(x => new Webhook(this.session, x)),
}
}
return new Member(this.session, member, this.id); async fetchOwner(): Promise<Member> {
} return this.fetchMember(this.ownerId);
}
/** fetches multiple members */ /** fetches a member */
async fetchMembers(options?: ListGuildMembers): Promise<Member[]> { async fetchMember(memberId: Snowflake): Promise<Member> {
const members = await this.session.rest.get<DiscordMemberWithUser[]>( const member = await this.session.rest.get<DiscordMemberWithUser>(
GUILD_MEMBERS(this.id, options) GUILD_MEMBER(this.id, memberId)
); );
return members.map((member) => new Member(this.session, member, this.id)); return new Member(this.session, member, this.id);
} }
/** fetches multiple members */
async fetchMembers(options?: ListGuildMembers): Promise<Member[]> {
const members = await this.session.rest.get<DiscordMemberWithUser[]>(
GUILD_MEMBERS(this.id, options)
);
return members.map((member) => new Member(this.session, member, this.id));
}
} }