This commit is contained in:
ITOH
2021-04-24 19:38:38 +02:00
parent 0feb6822d0
commit 03db98cd48
11 changed files with 40 additions and 43 deletions
+10 -6
View File
@@ -1,7 +1,7 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { DiscordChannel } from "../../types/channels/channel.ts";
import { Channel } from "../../types/channels/channel.ts";
import { CreateMessage } from "../../types/messages/create_message.ts";
import { endpoints } from "../../util/constants.ts";
import { sendMessage } from "../messages/send_message.ts";
@@ -14,11 +14,15 @@ export async function sendDirectMessage(
let dmChannel = await cacheHandlers.get("channels", memberId);
if (!dmChannel) {
// If not available in cache create a new one.
const dmChannelData = await rest.runMethod("post", endpoints.USER_DM, {
recipient_id: memberId,
});
const dmChannelData = await rest.runMethod<Channel>(
"post",
endpoints.USER_DM,
{
recipient_id: memberId,
},
);
const discordenoChannel = await structures.createDiscordenoChannel(
dmChannelData as DiscordChannel,
dmChannelData,
);
// Recreate the channel and add it undert he users id
await cacheHandlers.set("channels", memberId, discordenoChannel);
@@ -26,5 +30,5 @@ export async function sendDirectMessage(
}
// If it does exist try sending a message to this user
return sendMessage(dmChannel.id, content);
return await sendMessage(dmChannel.id, content);
}