forked from Dougley/slshx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractions.ts
101 lines (94 loc) · 3.44 KB
/
interactions.ts
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import type {
RESTGetAPIInteractionFollowupResult,
RESTGetAPIInteractionOriginalResponseResult,
RESTPatchAPIInteractionFollowupResult,
RESTPatchAPIInteractionOriginalResponseJSONBody,
RESTPatchAPIInteractionOriginalResponseResult,
RESTPostAPIInteractionFollowupJSONBody,
RESTPostAPIInteractionFollowupResult,
Snowflake,
} from "discord-api-types/v9";
import {
WithFileAttachments,
extractAttachments,
mergeFormData,
} from "../helpers";
import { call } from "./helpers";
/** @see https://discord.com/developers/docs/interactions/receiving-and-responding#get-original-interaction-response */
export function getOriginalInteractionResponse(
applicationId: Snowflake,
interactionToken: string
): Promise<RESTGetAPIInteractionOriginalResponseResult> {
return call(
"GET",
`/webhooks/${applicationId}/${interactionToken}/messages/@original`
);
}
/** @see https://discord.com/developers/docs/interactions/receiving-and-responding#edit-original-interaction-response */
export function editOriginalInteractionResponse(
applicationId: Snowflake,
interactionToken: string,
message: WithFileAttachments<RESTPatchAPIInteractionOriginalResponseJSONBody>
): Promise<RESTPatchAPIInteractionOriginalResponseResult> {
const body = mergeFormData(...extractAttachments(message));
return call(
"PATCH",
`/webhooks/${applicationId}/${interactionToken}/messages/@original`,
body
);
}
/** @see https://discord.com/developers/docs/interactions/receiving-and-responding#delete-original-interaction-response */
export function deleteOriginalInteractionResponse(
applicationId: Snowflake,
interactionToken: string
): Promise<void> {
return call(
"DELETE",
`/webhooks/${applicationId}/${interactionToken}/messages/@original`
);
}
/** @see https://discord.com/developers/docs/interactions/receiving-and-responding#create-followup-message */
export function createFollowupMessage(
applicationId: Snowflake,
interactionToken: string,
message: WithFileAttachments<RESTPostAPIInteractionFollowupJSONBody>
): Promise<RESTPostAPIInteractionFollowupResult> {
const body = mergeFormData(...extractAttachments(message));
return call("POST", `/webhooks/${applicationId}/${interactionToken}`, body);
}
/** @see https://discord.com/developers/docs/interactions/receiving-and-responding#get-followup-message */
export function getFollowupMessage(
applicationId: Snowflake,
interactionToken: string,
messageId: Snowflake
): Promise<RESTGetAPIInteractionFollowupResult> {
return call(
"GET",
`/webhooks/${applicationId}/${interactionToken}/messages/${messageId}`
);
}
/** @see https://discord.com/developers/docs/interactions/receiving-and-responding#edit-followup-message */
export function editFollowupMessage(
applicationId: Snowflake,
interactionToken: string,
messageId: Snowflake,
message: WithFileAttachments<RESTPatchAPIInteractionFollowupResult>
): Promise<RESTPatchAPIInteractionFollowupResult> {
const body = mergeFormData(...extractAttachments(message));
return call(
"PATCH",
`/webhooks/${applicationId}/${interactionToken}/messages/${messageId}`,
body
);
}
/** @see https://discord.com/developers/docs/interactions/receiving-and-responding#delete-followup-message */
export function deleteFollowupMessage(
applicationId: Snowflake,
interactionToken: string,
messageId: Snowflake
): Promise<void> {
return call(
"DELETE",
`/webhooks/${applicationId}/${interactionToken}/messages/${messageId}`
);
}