Updated autodeploy script to include contextmenu commands

This commit is contained in:
2024-09-12 20:20:50 +02:00
parent 0aba5e5195
commit da16275df4

View File

@@ -1,28 +1,34 @@
import { RESTPostAPIChatInputApplicationCommandsJSONBody } from "discord.js" import { RESTPostAPIChatInputApplicationCommandsJSONBody, RESTPostAPIContextMenuApplicationCommandsJSONBody } from "discord.js"
import fs from "fs" import fs from "fs"
import { ICommand } from "interfaces" import { ICommand, IContextMenu } from "interfaces"
import { ExtendedClient } from "./Client.js" import { ExtendedClient } from "./Client.js"
import env from "./Env.js" import env from "./Env.js"
import { color } from "./functions/colors.js" import { color } from "./functions/colors.js"
type FileType = "js" | "ts" type FileType = "js" | "ts"
export default async function autoDeployCommands(fileType: FileType, client: ExtendedClient) { export default async function autoDeployCommands(fileType: FileType, client: ExtendedClient) {
const commands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [] type CommandsType = RESTPostAPIChatInputApplicationCommandsJSONBody | RESTPostAPIContextMenuApplicationCommandsJSONBody
const commands: CommandsType[] = []
let commandFiles: string[] = [] let commandFiles: string[] = []
// let contentMenuCommands: string[] = [] let contentMenuCommands: string[] = []
if (fileType === "js") { if (fileType === "js") {
commandFiles = fs.readdirSync("./dist/commands/").filter(file => file.endsWith(fileType)) commandFiles = fs.readdirSync("./dist/commands/").filter(file => file.endsWith(fileType))
// contentMenuCommands = fs.readdirSync("./dist/commands-contextmenu/").filter(file => file.endsWith(fileType)) contentMenuCommands = fs.readdirSync("./dist/commands-contextmenu/").filter(file => file.endsWith(fileType))
} else if (fileType === "ts") { } else if (fileType === "ts") {
commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsWith(fileType)) commandFiles = fs.readdirSync("./src/commands/").filter(file => file.endsWith(fileType))
// contentMenuCommands = fs.readdirSync("./src/commands-contextmenu/").filter(file => file.endsWith(fileType)) contentMenuCommands = fs.readdirSync("./src/commands-contextmenu/").filter(file => file.endsWith(fileType))
} }
for (const file of commandFiles) { for (const file of commandFiles) {
// const command: ICommand = require(`../commands/${file}`) const { default: command } = await import(`../commands/${file}`) as { default: ICommand }
const { default: commandImport } = await import(`../commands/${file}`) if (command.dev) {
const command: ICommand = commandImport commands.push(command.data.toJSON())
}
}
for (const file of contentMenuCommands) {
const { default: command } = await import(`../commands-contextmenu/${file}`) as { default: IContextMenu }
if (command.dev) { if (command.dev) {
commands.push(command.data.toJSON()) commands.push(command.data.toJSON())
} }
@@ -31,27 +37,25 @@ export default async function autoDeployCommands(fileType: FileType, client: Ext
const commandData = commands.map(command => { const commandData = commands.map(command => {
return { return {
name: command.name, name: command.name,
description: command.description,
options: command.options?.map(option => { options: command.options?.map(option => {
return { return {
name: option.name, name: option.name,
description: option.description, description: option.description,
type: option.type type: option.type
} }
}), }) ?? [],
defaultPermission: command.default_member_permissions ?? null defaultPermission: command.default_member_permissions ?? null
} }
}).sort((a, b) => a.name > b.name ? 1 : -1) }).sort((a, b) => a.name > b.name ? 1 : -1)
client.on("ready", async (c) => { client.on("ready", async (c) => {
const guildclient = c.guilds.cache.get(env.dev.guildid)! const guildclient = c.guilds.cache.get(env.dev.guildid)!
const currentCommands = await guildclient.commands.fetch() const currentCommands = await guildclient.commands.fetch({})
if (!currentCommands) return if (!currentCommands) return
const currentCommandsData = currentCommands.map(command => { const currentCommandsData = currentCommands.map(command => {
return { return {
name: command.name, name: command.name,
description: command.description,
options: command.options?.map(option => { options: command.options?.map(option => {
return { return {
name: option.name, name: option.name,