-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add updateInteractions hook to discord Module
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ApplicationCommandDataResolvable, Guild } from "discord.js"; | ||
import ExtendedClient, { DSInteraction } from "../../extendedclient"; | ||
import { error, info } from "@src/engine/utils/Logger"; | ||
interface CleanInteraction { | ||
name: string; | ||
description?: string; | ||
registerTo?: DSInteraction["registerTo"]; | ||
} | ||
|
||
export default async function updateInteractions(client: ExtendedClient, params: { guild?: Guild } | undefined) { | ||
const guild = params?.guild; | ||
if (!guild) { | ||
const arr: ApplicationCommandDataResolvable[] = []; | ||
for await (const [, interaction] of client.interactions.entries()) { | ||
const cleanInt: CleanInteraction = { | ||
name: interaction.name, | ||
registerTo: interaction.registerTo, | ||
} | ||
cleanInt.description = interaction.type == "chat" ? undefined : interaction.description; | ||
} | ||
client.application?.commands.set(arr).catch((e) => { | ||
error("Error while updating App Interactions: ", e); | ||
}); | ||
info("Updated App Interactions"); | ||
return; | ||
} | ||
const arr = []; | ||
for await (const [, interaction] of client.interactions.entries()) { | ||
const cleanInt: CleanInteraction = { | ||
name: interaction.name, | ||
registerTo: interaction.registerTo, | ||
} | ||
cleanInt.description = interaction.type == "chat" ? undefined : interaction.description; | ||
if (cleanInt.registerTo == "guild") arr.push(cleanInt); | ||
} | ||
await guild.commands.set(arr as ApplicationCommandDataResolvable[]).catch((e) => { | ||
error("Found Guild but couldn't Update Interactions", e); | ||
}); | ||
info("Updated Interactions for", guild.name); | ||
} |