fix: dm typings

This commit is contained in:
Skillz4Killz
2021-04-12 18:15:34 +00:00
committed by GitHub
parent 7e38960e9a
commit 638979950b
+5 -3
View File
@@ -1,22 +1,24 @@
import { cacheHandlers } from "../../cache.ts"; import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts"; import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts"; import { structures } from "../../structures/mod.ts";
import { DiscordChannel } from "../../types/channels/channel.ts";
import { CreateMessage } from "../../types/messages/create_message.ts";
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { sendMessage } from "../messages/send_message.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. */ /** 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( export async function sendDirectMessage(
memberId: string, memberId: string,
content: string | MessageContent, content: string | CreateMessage,
) { ) {
let dmChannel = await cacheHandlers.get("channels", memberId); let dmChannel = await cacheHandlers.get("channels", memberId);
if (!dmChannel) { if (!dmChannel) {
// If not available in cache create a new one. // If not available in cache create a new one.
const dmChannelData = await rest.runMethod("post", endpoints.USER_DM, { const dmChannelData = await rest.runMethod("post", endpoints.USER_DM, {
recipient_id: memberId, recipient_id: memberId,
}) as DMChannelCreatePayload; });
const discordenoChannel = await structures.createDiscordenoChannel( const discordenoChannel = await structures.createDiscordenoChannel(
dmChannelData as unknown as DiscordChannel, dmChannelData as DiscordChannel,
); );
// Recreate the channel and add it undert he users id // Recreate the channel and add it undert he users id
await cacheHandlers.set("channels", memberId, discordenoChannel); await cacheHandlers.set("channels", memberId, discordenoChannel);