User Preferences and Setup Docs (#20)
* added message style command * docker setup scripts * reformat messageStyle.ts * fix: register unregister on deploy * add: messageStream preference * add: json config handler * update: messageCreate gets config * update: shifted chat to config callback * fix: naming conventions based on discord * update: setup in docs now * add: static docker ips * version increment * add: bot message for no config * fix: no config case * add: clarification for subnetting * update: version increment in lock file --------- Co-authored-by: JT2M0L3Y <jtsmoley@icloud.com>
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import { CommandInteraction, ChatInputApplicationCommandData, Client } from 'discord.js'
|
||||
import { CommandInteraction, ChatInputApplicationCommandData, Client, ApplicationCommandOption } from 'discord.js'
|
||||
|
||||
/**
|
||||
* interface for how slash commands should be run
|
||||
*/
|
||||
export interface SlashCommand extends ChatInputApplicationCommandData {
|
||||
run: (client: Client, interaction: CommandInteraction) => void
|
||||
run: (
|
||||
client: Client,
|
||||
interaction: CommandInteraction,
|
||||
options?: ApplicationCommandOption[]
|
||||
) => void
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -16,7 +20,28 @@ export function registerCommands(client: Client, commands: SlashCommand[]): void
|
||||
// ensure the bot is online before registering
|
||||
if (!client.application) return
|
||||
|
||||
// map commands into an array of names, used to checking registered commands
|
||||
const commandsToRegister: string[] = commands.map(command => command.name)
|
||||
|
||||
// fetch all the commands and delete them
|
||||
client.application.commands.fetch().then((fetchedCommands) => {
|
||||
for (const command of fetchedCommands.values()) {
|
||||
if (!commandsToRegister.includes(command.name)) {
|
||||
command.delete().catch(console.error)
|
||||
console.log(`[Command: ${command.name}] Removed from Discord`)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// clear the cache of the commands
|
||||
client.application.commands.cache.clear()
|
||||
|
||||
// iterate through all commands and register them with the bot
|
||||
for (const command of commands)
|
||||
client.application.commands.create(command)
|
||||
client.application.commands
|
||||
.create(command)
|
||||
.then((c) => {
|
||||
console.log(`[Command: ${c.name}] Registered on Discord`)
|
||||
c.options?.forEach((o) => console.log(` - ${o.name}`))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user