fix: prevent sending dm to bot itself #1103

This commit is contained in:
Skillz4Killz
2021-09-13 02:28:47 +00:00
committed by GitHub
parent fec307afa0
commit 7642eab7bd
2 changed files with 5 additions and 0 deletions

View File

@@ -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.

View File

@@ -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",
}