【问题标题】:fs.watch auto reload commands on discord botfs.watch 不和谐机器人上的自动重新加载命令
【发布时间】:2019-04-11 10:16:03
【问题描述】:

我一直在研究我的 Discord Bot Rxiqi,并且我一直想要在文件更改时自动重新加载命令...我的代码是

var folder = "./commands/";
fs.watch(folder, { encoding: 'UTF-8' }, (eventType, filename) => {
    if (eventType ==="change") {
        console.log(`Updating Command: ${folder+filename}`)
        delete require.cache[require.resolve(folder+filename)];
        client.commands.delete(folder+filename);
        const props = require(filename);
        client.commands.set(folder+filename,props);
    }
});

但我不断得到这个控制台输出:

Updating Command: ./commands/adverts.js
Error: Cannot find module './commands/adverts.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.resolve (internal/module.js:18:19)
    at FSWatcher.fs.watch (E:\BotDevelopment\Rxiqi\status\ready.js:62:38)
    at emitTwo (events.js:126:13)
    at FSWatcher.emit (events.js:214:7)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1364:12)
Updating Command: ./commands/adverts.js
Error: Cannot find module './commands/adverts.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.resolve (internal/module.js:18:19)
    at FSWatcher.fs.watch (E:\BotDevelopment\Rxiqi\status\ready.js:62:38)
    at emitTwo (events.js:126:13)
    at FSWatcher.emit (events.js:214:7)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1364:12)

非常感谢任何帮助:)

【问题讨论】:

  • const props = require(filename); 行应该是 const props = require(folder + filename); ,可能
  • 不,仍然返回完全相同的错误堆栈。感谢您尝试 :)

标签: node.js fs discord.js


【解决方案1】:

您使用的是什么操作系统?如果您在 Windows 上,则会出现问题,因为您的 '/' 将不起作用

【讨论】:

  • Windows 10,但我的重新加载命令没有这个问题,它使用相同的布局。
猜你喜欢
  • 2017-04-01
  • 1970-01-01
  • 2018-07-21
  • 2018-11-10
  • 2017-05-31
  • 2021-10-21
  • 2022-01-15
  • 2021-06-17
  • 2019-09-04
相关资源
最近更新 更多