use paths relative to modules

This commit is contained in:
Chipmunk 2024-04-04 22:00:51 -04:00
parent 52573e21bc
commit f2231a48a4
2 changed files with 5 additions and 5 deletions

4
bot.js
View file

@ -4,9 +4,9 @@ const fs = require('fs')
const path = require('path')
const plugins = []
for (const filename of fs.readdirSync('plugins')) {
for (const filename of fs.readdirSync(path.resolve(__dirname, 'plugins'))) {
if (!filename.endsWith('.js')) return
plugins.push(require(path.resolve('plugins', filename)))
plugins.push(require(path.resolve(__dirname, 'plugins', filename)))
}
function createBot (options = {}) {

View file

@ -10,8 +10,8 @@ let commands
function loadCommands () {
commands = []
fs.readdirSync('commands').forEach(filename => {
const filepath = path.resolve('commands', filename)
for (const filename of fs.readdirSync(path.resolve(__dirname, '..', 'commands'))) {
const filepath = path.resolve(__dirname, '..', 'commands', filename)
if (!filepath.endsWith('.js') || !fs.statSync(filepath).isFile()) return
try {
delete require.cache[require.resolve(filepath)]
@ -19,7 +19,7 @@ function loadCommands () {
} catch (error) {
console.error('Error loading command', filepath, ':', error)
}
})
}
}
loadCommands()