【问题标题】:Discord.js: Error telling me the command file doesn't existDiscord.js:错误告诉我命令文件不存在
【发布时间】:2021-05-29 21:06:36
【问题描述】:

我正在制作一个不和谐的机器人并关注 Worn Off Keys 的视频。在第二集中,我遇到了一个错误。我什至复制并粘贴了他 github 上的代码,但它仍然不起作用。以下是我拥有的东西:

我的代码:

const Discord = require('discord.js')
const client = new Discord.Client()

const config = require('./config.json')
const command = require('./command')

client.on('ready', () => {
  console.log(`${client.user.username} is up and running.`)

  command(client, ['ping', 'test'], (message) => {
    message.channel.send('shut up idc')
  })
})

client.login(config.token)

这是我得到的错误:

Error: Cannot find module './command'
Require stack:
- /home/runner/discord-bot-2/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at /home/runner/discord-bot-2/index.js:5:17
    at Script.runInContext (vm.js:130:18)
    at Object.<anonymous> (/run_dir/interp.js:209:20)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)

【问题讨论】:

    标签: javascript node.js discord.js modulenotfounderror


    【解决方案1】:

    您的 index.js 或用于运行所有内容的主要 JavaScript 文件位于何处?我遇到了类似的问题,但不得不将我的 bot.js 文件从它所在的 src 文件夹中移到主目录区域中。问题与通过 fs 访问的文件有关,我能够将其缩小为文件访问错误,它无法从主文件中提取必要的 Discord 功能,因为它位于另一个文件夹而不是顶层访问。让我知道这是否有帮助。

    【讨论】:

      【解决方案2】:

      我得到了答案!我只需要将命令文件从我放入的文件夹中取出。

      【讨论】:

        猜你喜欢
        • 2021-06-02
        • 2021-02-27
        • 2020-12-05
        • 1970-01-01
        • 2017-01-16
        • 2021-09-12
        • 2013-11-20
        • 2021-06-09
        • 1970-01-01
        相关资源
        最近更新 更多