discord bot,错误discordie未定义

时间:2016-12-11 00:19:33

标签: node.js bots discord

我最近开始为不和谐制作自己的机器人。现在我对NodeJS很新,但不是Javascript。我已经安装了我所知道的机器人所需的所有软件包,但它仍然无法正常工作。我安装了:Nodemon和Discordie。现在我收到这个错误:

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\Vade>npm run Spicii

> discord-bot-SpiciiBott@3.10.10 Spicii C:\Users\Vade
> nodemon bot.js

[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node bot.js`

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "Spicii"
npm ERR! node v7.2.1
npm ERR! npm  vundefined
npm ERR! code ELIFECYCLE
npm ERR! discord-bot-SpiciiBott@3.10.10 Spicii: `nodemon bot.js`
npm ERR! Exit status 3221226356
npm ERR!
npm ERR! Failed at the discord-bot-SpiciiBott@3.10.10 Spicii script 'nodemon bot.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the discord-bot-SpiciiBott package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     nodemon bot.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs discord-bot-SpiciiBott
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls discord-bot-SpiciiBott
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\Vade\npm-debug.log

C:\Users\Vade>C:\Users\Vade\bot.js:3
const Events = Discordie.Events;
               ^

ReferenceError: Discordie is not defined
    at Object.<anonymous> (C:\Users\Vade\bot.js:3:16)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:420:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:535:3

但如果我改变错误&#34; const Events = Discordie.Events;&#34; to&#34; const Events = discordie.Events;&#34;我明白了:

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\Vade>npm run Spicii

> discord-bot-SpiciiBott@3.10.10 Spicii C:\Users\Vade
> nodemon bot.js

[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node bot.js`

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "Spicii"
npm ERR! node v7.2.1
npm ERR! npm  vundefined
npm ERR! code ELIFECYCLE
npm ERR! discord-bot-SpiciiBott@3.10.10 Spicii: `nodemon bot.js`
npm ERR! Exit status 3221226356
npm ERR!
npm ERR! Failed at the discord-bot-SpiciiBott@3.10.10 Spicii script 'nodemon bot.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the discord-bot-SpiciiBott package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     nodemon bot.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs discord-bot-SpiciiBott
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls discord-bot-SpiciiBott
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\Vade\npm-debug.log

C:\Users\Vade>C:\Users\Vade\node_modules\discordie\lib\collections\UnavailableGuildCollection.js:119
    discordie.Dispatcher.on(Events.GATEWAY_DISPATCH, e => {
                        ^

TypeError: Cannot read property 'on' of undefined
    at UnavailableGuildCollection (C:\Users\Vade\node_modules\discordie\lib\collections\UnavailableGuildCollection.js:119:25)
    at UnavailableGuildCollection.splice (<anonymous>)
    at UnavailableGuildCollection.removeUnavailable (C:\Users\Vade\node_modules\discordie\lib\collections\UnavailableGuildCollection.js:107:8)
    at UnavailableGuildCollection.handleUnavailable (C:\Users\Vade\node_modules\discordie\lib\collections\UnavailableGuildCollection.js:92:23)
    at UnavailableGuildCollection.handleGuildCreate (C:\Users\Vade\node_modules\discordie\lib\collections\UnavailableGuildCollection.js:72:21)
    at Object.bindGatewayEventHandlers (C:\Users\Vade\node_modules\discordie\lib\core\Utils.js:34:17)
    at DiscordieDispatcher.UnavailableGuildCollection.discordie.Dispatcher.on.e (C:\Users\Vade\node_modules\discordie\lib\collections\UnavailableGuildCollection.js:122:13)
    at emitOne (events.js:101:20)
    at DiscordieDispatcher.emit (events.js:188:7)
    at DiscordieDispatcher.emit (C:\Users\Vade\node_modules\discordie\lib\core\DiscordieDispatcher.js:36:16)

请帮助我不知道我错过了什么。继承了机器人本身的代码:

var discordie = require("discordie");

const Events = Discordie.Events;
const client = new Discordie();

client.connect({
  token: "MjU2OTAyODY5NDc3ODgzOTA1.CyzDRg.wJXmGfqxKd6kMcBXi49asUi0zt0"
})

client.Dispatcher.on(Events.GATEWAY_READY, e => {
  console.log("Connected as: " + client.User.username);
});

client.Dispatcher.on(Events.MESSAGE_CREATE, e =>  {
  if(e.message.content == "PING") {
    e.message.channel.sendMessage("PONG");

  }
});

1 个答案:

答案 0 :(得分:1)

您很可能没有安装discordie,请输入nodejs控制台npm install discordie