This repository has been archived by the owner on May 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.ts
36 lines (35 loc) · 1.59 KB
/
handler.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
import {InteractionResponseType, InteractionType} from 'discord-interactions'
export async function handleInteract(json: any, request: Request): Promise<Response> {
if (json.type == InteractionType.PING) {
// This is required for Discord to validate your bot - don't remove it.
return new Response(JSON.stringify({type: InteractionResponseType.PONG}))
} else if (json.type == InteractionType.APPLICATION_COMMAND) {
switch (json.data.name) {
case 'echo':
return new Response(
JSON.stringify({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
tts: false,
content: json.data.options[0].value, // we should be pulling based on the `name` property, actually
embeds: [],
allow_mentions: {parse: []},
},
}),
)
default:
return new Response(
JSON.stringify({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
tts: false,
content: 'Sorry, we experienced a problem and a command was sent that doesn\'t exist!',
embeds: [],
allow_mentions: {parse: []},
},
}),
)
}
}
return new Response(`request method: ${request.method}`)
}