This repository has been archived by the owner on Sep 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract sendResponse into its own function (#366)
See #366
- Loading branch information
Showing
2 changed files
with
30 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import axios from "axios"; | ||
import { APIGuildInteraction, APIInteractionResponse } from "discord-api-types"; | ||
import logger from "../logger"; | ||
|
||
export async function sendResponse( | ||
event: APIGuildInteraction, | ||
response: string, | ||
ephemeral = false | ||
): Promise<void> { | ||
const payload: APIInteractionResponse = { | ||
type: 4, | ||
data: { content: response }, | ||
}; | ||
if (ephemeral) { | ||
payload.data.flags = 64; | ||
} | ||
logger.debug("[interactions] sending response: ", payload); | ||
return axios.post( | ||
`https://discord.com/api/v8/interactions/${event.id}/${event.token}/callback`, | ||
payload, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
); | ||
} |