-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmessages.tsx
62 lines (57 loc) · 1.91 KB
/
messages.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type {
RESTGetAPIChannelMessageResult,
RESTGetAPIChannelMessagesQuery,
RESTGetAPIChannelMessagesResult,
RESTPostAPIChannelMessageJSONBody,
RESTPostAPIChannelMessageResult,
} from "discord-api-types/v10";
import { Routes } from "discord-api-types/v10";
import type { Snowflake } from "discord-snowflake";
import { client } from "../client.js";
/**
* Returns an array of Messages for a Channel.
* {@link https://discord.com/developers/docs/resources/channel#get-channel-messages | Discord Documentation}
* @param channelId - The target Channel to get Messages in.
* @returns An array of Messages
*/
export async function getMessages(
channelId: Snowflake,
params?: RESTGetAPIChannelMessagesQuery
) {
const query = new URLSearchParams();
if (params) {
Object.entries(params).forEach(([key, value]) => {
query.set(key, value);
});
}
return client.get(Routes.channelMessages(channelId), {
query,
}) as Promise<RESTGetAPIChannelMessagesResult>;
}
/**
* Get a Message.
* {@link https://discord.com/developers/docs/resources/channel#get-channel-message | Discord Documentation}
* @param channelId - The target Channel to get the Message in.
* @param messageId - The target Message to get.
* @returns The Message.
*/
export async function getMessage(channelId: Snowflake, messageId: Snowflake) {
return client.get(
Routes.channelMessage(channelId, messageId)
) as Promise<RESTGetAPIChannelMessageResult>;
}
/**
* Posts a Message to a Channel.
* {@link https://discord.com/developers/docs/resources/channel#create-message | Discord Documentation}
* @param channelId - The target Channel to post the Message in.
* @param data - The Message content.
* @returns The created Message.
*/
export async function createMessage(
channelId: Snowflake,
data: RESTPostAPIChannelMessageJSONBody
) {
return client.post(Routes.channelMessages(channelId), {
body: data,
}) as Promise<RESTPostAPIChannelMessageResult>;
}