lunaticboy
lunaticboy
DIAdiscord.js - Imagine an app
Created by lunaticboy on 1/22/2024 in #djs-questions
command deploy stucked
Thanks! I think you're right. I restarted the bot more than 50 times today to fix the FeelsBadMan
7 replies
DIAdiscord.js - Imagine an app
Created by lunaticboy on 1/22/2024 in #djs-questions
command deploy stucked
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { REST } from '@discordjs/rest'
import { RESTPostAPIApplicationCommandsJSONBody, Routes } from 'discord.js'
import { readdirSync } from 'fs'
import type ApplicationCommand from './templates/ApplicationCommand.js'
const { TOKEN, CLIENT_ID } = process.env

export default async function deployGlobalCommands() {
const commands: RESTPostAPIApplicationCommandsJSONBody[] = []
const commandFiles: string[] = readdirSync('./commands').filter(
(file) => file.endsWith('.js') || file.endsWith('.ts')
)

for (const file of commandFiles) {
const command: ApplicationCommand = (await import(`./commands/${file}`))
.default as ApplicationCommand
const commandData = command.data.toJSON()
commands.push(commandData)
}

const rest = new REST({ version: '10' }).setToken(TOKEN as string)

try {
console.log('Started refreshing application (/) commands.')

await rest.put(Routes.applicationCommands(CLIENT_ID as string), {
body: []
})

await rest.put(Routes.applicationCommands(CLIENT_ID as string), {
body: commands
})

console.log('Successfully reloaded application (/) commands.')
} catch (error) {
console.error(error)
}
}
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { REST } from '@discordjs/rest'
import { RESTPostAPIApplicationCommandsJSONBody, Routes } from 'discord.js'
import { readdirSync } from 'fs'
import type ApplicationCommand from './templates/ApplicationCommand.js'
const { TOKEN, CLIENT_ID } = process.env

export default async function deployGlobalCommands() {
const commands: RESTPostAPIApplicationCommandsJSONBody[] = []
const commandFiles: string[] = readdirSync('./commands').filter(
(file) => file.endsWith('.js') || file.endsWith('.ts')
)

for (const file of commandFiles) {
const command: ApplicationCommand = (await import(`./commands/${file}`))
.default as ApplicationCommand
const commandData = command.data.toJSON()
commands.push(commandData)
}

const rest = new REST({ version: '10' }).setToken(TOKEN as string)

try {
console.log('Started refreshing application (/) commands.')

await rest.put(Routes.applicationCommands(CLIENT_ID as string), {
body: []
})

await rest.put(Routes.applicationCommands(CLIENT_ID as string), {
body: commands
})

console.log('Successfully reloaded application (/) commands.')
} catch (error) {
console.error(error)
}
}
deploy code
7 replies