mirror of
https://github.com/swc-project/swc.git
synced 2024-12-21 12:41:54 +03:00
d60c3242af
swc_bundler: - Fix cycle detection for complex circular imports. (denoland/deno#10752) swc_ecma_transforms_typescript: - Allow using large values for an enum variant.
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
// Loaded from https://deno.land/x/discordeno@11.0.0-rc.2/src/helpers/messages/get_messages.ts
|
|
|
|
|
|
import { rest } from "../../rest/rest.ts";
|
|
import { structures } from "../../structures/mod.ts";
|
|
import { Errors } from "../../types/discordeno/errors.ts";
|
|
import {
|
|
GetMessagesAfter,
|
|
GetMessagesAround,
|
|
GetMessagesBefore,
|
|
GetMessagesLimit,
|
|
} from "../../types/messages/get_messages.ts";
|
|
import type { Message } from "../../types/messages/message.ts";
|
|
import { endpoints } from "../../util/constants.ts";
|
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
|
|
|
/** Fetches between 2-100 messages. Requires VIEW_CHANNEL and READ_MESSAGE_HISTORY */
|
|
export async function getMessages(
|
|
channelId: bigint,
|
|
options?: GetMessagesAfter | GetMessagesBefore | GetMessagesAround | GetMessagesLimit
|
|
) {
|
|
await requireBotChannelPermissions(channelId, ["VIEW_CHANNEL", "READ_MESSAGE_HISTORY"]);
|
|
|
|
if (options?.limit && (options.limit < 0 || options.limit > 100)) {
|
|
throw new Error(Errors.INVALID_GET_MESSAGES_LIMIT);
|
|
}
|
|
|
|
const result = await rest.runMethod<Message[]>("get", endpoints.CHANNEL_MESSAGES(channelId), options);
|
|
|
|
return await Promise.all(result.map((res) => structures.createDiscordenoMessage(res)));
|
|
}
|