fix: sendInteractionResponse

This commit is contained in:
ITOH
2021-06-06 17:58:08 +02:00
parent c44fd79bbe
commit f7abbc4713
@@ -14,17 +14,6 @@ import { snakelize, validateComponents } from "../../util/utils.ts";
export async function sendInteractionResponse(id: bigint, token: string, options: DiscordenoInteractionResponse) {
// TODO: add more options validations
if (options.data?.components) validateComponents(options.data?.components);
// If its already been executed, we need to send a followup response
if (cache.executedSlashCommands.has(token)) {
return await rest.runMethod("post", endpoints.WEBHOOK(applicationId, token), snakelize(options));
}
// Expire in 15 minutes
cache.executedSlashCommands.add(token);
setTimeout(() => {
eventHandlers.debug?.("loop", `Running setTimeout in send_interaction_response file.`);
cache.executedSlashCommands.delete(token);
}, 900000);
// If the user wants this as a private message mark it ephemeral
if (options.private) {
@@ -36,5 +25,17 @@ export async function sendInteractionResponse(id: bigint, token: string, options
options.data = { ...options.data, allowedMentions: { parse: [] } };
}
// If its already been executed, we need to send a followup response
if (cache.executedSlashCommands.has(token)) {
return await rest.runMethod("post", endpoints.WEBHOOK(applicationId, token), snakelize(options.data));
}
// Expire in 15 minutes
cache.executedSlashCommands.add(token);
setTimeout(() => {
eventHandlers.debug?.("loop", `Running setTimeout in send_interaction_response file.`);
cache.executedSlashCommands.delete(token);
}, 900000);
return await rest.runMethod("post", endpoints.INTERACTION_ID_TOKEN(id, token), snakelize(options));
}