support string as id

This commit is contained in:
ITOH
2021-06-11 21:16:10 +02:00
parent 8f70ce52ca
commit 86375fe54b
@@ -5,13 +5,18 @@ import type { DiscordenoInteractionResponse } from "../../types/discordeno/inter
import { endpoints } from "../../util/constants.ts"; import { endpoints } from "../../util/constants.ts";
import { snakelize, validateComponents } from "../../util/utils.ts"; import { snakelize, validateComponents } from "../../util/utils.ts";
// TODO: v12 remove | string
/** /**
* Send a response to a users slash command. The command data will have the id and token necessary to respond. * Send a response to a users slash command. The command data will have the id and token necessary to respond.
* Interaction `tokens` are valid for **15 minutes** and can be used to send followup messages. * Interaction `tokens` are valid for **15 minutes** and can be used to send followup messages.
* *
* NOTE: By default we will suppress mentions. To enable mentions, just pass any mentions object. * NOTE: By default we will suppress mentions. To enable mentions, just pass any mentions object.
*/ */
export async function sendInteractionResponse(id: bigint, token: string, options: DiscordenoInteractionResponse) { export async function sendInteractionResponse(
id: bigint | string,
token: string,
options: DiscordenoInteractionResponse
) {
// TODO: add more options validations // TODO: add more options validations
if (options.data?.components) validateComponents(options.data?.components); if (options.data?.components) validateComponents(options.data?.components);
@@ -37,5 +42,9 @@ export async function sendInteractionResponse(id: bigint, token: string, options
cache.executedSlashCommands.delete(token); cache.executedSlashCommands.delete(token);
}, 900000); }, 900000);
return await rest.runMethod("post", endpoints.INTERACTION_ID_TOKEN(id, token), snakelize(options)); return await rest.runMethod(
"post",
endpoints.INTERACTION_ID_TOKEN(typeof id === "bigint" ? id : BigInt(id), token),
snakelize(options)
);
} }