diff --git a/src/helpers/members/send_direct_message.ts b/src/helpers/members/send_direct_message.ts index e00db4b3f..d38a6027d 100644 --- a/src/helpers/members/send_direct_message.ts +++ b/src/helpers/members/send_direct_message.ts @@ -1,13 +1,17 @@ +import { botId } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; import { rest } from "../../rest/rest.ts"; import { structures } from "../../structures/mod.ts"; import type { Channel } from "../../types/channels/channel.ts"; import type { CreateMessage } from "../../types/messages/create_message.ts"; +import { Errors } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { sendMessage } from "../messages/send_message.ts"; /** Send a message to a users DM. Note: this takes 2 API calls. 1 is to fetch the users dm channel. 2 is to send a message to that channel. */ export async function sendDirectMessage(memberId: bigint, content: string | CreateMessage) { + if (memberId === botId) throw new Error(Errors.YOU_CAN_NOT_DM_THE_BOT_ITSELF); + let dmChannel = await cacheHandlers.get("channels", memberId); if (!dmChannel) { // If not available in cache create a new one. diff --git a/src/types/discordeno/errors.ts b/src/types/discordeno/errors.ts index fa6a5720a..fea8a099c 100644 --- a/src/types/discordeno/errors.ts +++ b/src/types/discordeno/errors.ts @@ -118,4 +118,5 @@ export enum Errors { CANNOT_ADD_USER_TO_ARCHIVED_THREADS = "CANNOT_ADD_USER_TO_ARCHIVED_THREADS", CANNOT_LEAVE_ARCHIVED_THREAD = "CANNOT_LEAVE_ARCHIVED_THREAD", CANNOT_REMOVE_FROM_ARCHIVED_THREAD = "CANNOT_REMOVE_FROM_ARCHIVED_THREAD", + YOU_CAN_NOT_DM_THE_BOT_ITSELF = "YOU_CAN_NOT_DM_THE_BOT_ITSELF", }