ales
ales
DIAdiscord.js - Imagine an app
Created by ales on 2/25/2024 in #djs-questions
Converting the Command Handler and the Command Deployer to use ES modules
thank you!
11 replies
DIAdiscord.js - Imagine an app
Created by ales on 2/25/2024 in #djs-questions
Converting the Command Handler and the Command Deployer to use ES modules
i'll go with that then
11 replies
DIAdiscord.js - Imagine an app
Created by ales on 2/25/2024 in #djs-questions
Converting the Command Handler and the Command Deployer to use ES modules
oh ok, maybe i'll update then
11 replies
DIAdiscord.js - Imagine an app
Created by ales on 2/25/2024 in #djs-questions
Converting the Command Handler and the Command Deployer to use ES modules
thank you!
11 replies
DIAdiscord.js - Imagine an app
Created by ales on 2/25/2024 in #djs-questions
Converting the Command Handler and the Command Deployer to use ES modules
im having issues sending the command-handler.js code but it's the exact same as the guide, I just changed the imports
11 replies
DIAdiscord.js - Imagine an app
Created by ales on 2/25/2024 in #djs-questions
Converting the Command Handler and the Command Deployer to use ES modules
Command Handler in index.js:
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] })

client.commands = new Collection()

const foldersPath = path.join(__dirname, 'commands')
const commandFolders = fs.readdirSync(foldersPath)

for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder)
const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith('.js'))
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file)
const command = require(filePath)
// Set a new item in the Collection with the key as the command name and the value as the exported module
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command)
} else {
console.log(
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
)
}
}
}
// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds] })

client.commands = new Collection()

const foldersPath = path.join(__dirname, 'commands')
const commandFolders = fs.readdirSync(foldersPath)

for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder)
const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith('.js'))
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file)
const command = require(filePath)
// Set a new item in the Collection with the key as the command name and the value as the exported module
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command)
} else {
console.log(
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
)
}
}
}
11 replies