0
我最近開始做自己的機器人不和諧。現在我很新的NodeJS,但不是Javascript。我已經安裝了我所知道的機器人所需的所有軟件包,但它仍然不起作用。我已經安裝:Nodemon和Discordie。現在我只收到此錯誤:不一致bot,錯誤discordie沒有定義
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.
C:\Users\Vade>npm run Spicii
> [email protected] 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! [email protected] Spicii: `nodemon bot.js`
npm ERR! Exit status 3221226356
npm ERR!
npm ERR! Failed at the [email protected] 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
但是,如果我改變錯誤「常量活動= Discordie.Events;」到「const Events = discordie.Events;」我得到:
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.
C:\Users\Vade>npm run Spicii
> [email protected] 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! [email protected] Spicii: `nodemon bot.js`
npm ERR! Exit status 3221226356
npm ERR!
npm ERR! Failed at the [email protected] 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");
}
});
在您的代碼類型,你存儲'「discordie」'庫作爲小寫'discordie',所以你必須在代碼中用小寫變量引用它,而不是大寫。這就是爲什麼你會得到'Discordie沒有定義' –