diff --git a/src/helpers/messages/get_messages.ts b/src/helpers/messages/get_messages.ts index 79b29d238..ab3112865 100644 --- a/src/helpers/messages/get_messages.ts +++ b/src/helpers/messages/get_messages.ts @@ -1,5 +1,6 @@ import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; +import { Errors } from "../../types/discordeno/errors.ts"; import { GetMessagesAfter, GetMessagesAround, @@ -24,7 +25,9 @@ export async function getMessages( "READ_MESSAGE_HISTORY", ]); - if (options?.limit && options.limit > 100) return; + if (options?.limit && (options.limit < 0 || options.limit > 100)) { + throw new Error(Errors.INVALID_GET_MESSAGES_LIMIT); + } const result = await rest.runMethod( "get", diff --git a/src/types/discordeno/errors.ts b/src/types/discordeno/errors.ts index 34c50ccea..5fc9c0ef7 100644 --- a/src/types/discordeno/errors.ts +++ b/src/types/discordeno/errors.ts @@ -23,6 +23,8 @@ export enum Errors { GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS = "GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS", NOT_A_THREAD_CHANNEL = "NOT_A_THREAD_CHANNEL", + // Message Get Errors + INVALID_GET_MESSAGES_LIMIT = "INVALID_GET_MESSAGES_LIMIT", // Message Delete Errors DELETE_MESSAGES_MIN = "DELETE_MESSAGES_MIN", PRUNE_MIN_DAYS = "PRUNE_MIN_DAYS", diff --git a/src/types/messages/get_messages.ts b/src/types/messages/get_messages.ts index 9231d5577..f19dfa542 100644 --- a/src/types/messages/get_messages.ts +++ b/src/types/messages/get_messages.ts @@ -7,19 +7,19 @@ export interface GetMessagesLimit { /** https://discord.com/developers/docs/resources/channel#get-channel-messages-query-string-params */ export interface GetMessagesAround extends GetMessagesLimit { /** Get messages around this message id */ - around?: string; + around?: bigint; } /** https://discord.com/developers/docs/resources/channel#get-channel-messages-query-string-params */ export interface GetMessagesBefore extends GetMessagesLimit { /** Get messages before this message id */ - before?: string; + before?: bigint; } /** https://discord.com/developers/docs/resources/channel#get-channel-messages-query-string-params */ export interface GetMessagesAfter extends GetMessagesLimit { /** Get messages after this message id */ - after?: string; + after?: bigint; } /** https://discord.com/developers/docs/resources/channel#get-channel-messages-query-string-params */ diff --git a/tests/messages/get_messages.ts b/tests/messages/get_messages.ts index 4da2e6c3a..6c0b73b07 100644 --- a/tests/messages/get_messages.ts +++ b/tests/messages/get_messages.ts @@ -39,7 +39,7 @@ Deno.test({ // Fetch the messages const fetchedMessages = await getMessages(tempData.channelId, { - after: message.id.toString(), + after: message.id, limit: 2, }); // Check if getMessages has worked