0
我在JS中做了一個不和諧的機器人,我不斷收到這個錯誤,不管我嘗試了什麼,我已經研究過,它似乎只是讓我得到它。TypeError:bot.on不是函數
這是錯誤:
TypeError: bot.on is not a function
at Object.<anonymous> (C:\Users\quinb\Desktop\Supreme\bot.js:6:5)
at Module._compile (module.js:573:30)
at Object.Module._extensions..js (module.js:584:10)
at Module.load (module.js:507:32)
at tryModuleLoad (module.js:470:12)
at Function.Module._load (module.js:462:3)
at Function.Module.runMain (module.js:609:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:598:3
C:\Users\quinb\Desktop\Supreme>pause
這是我的機器人批處理啓動代碼:
node bot.js
pause
這是我的機器人的JavaScript代碼:
const botSettings = require("./botsettings.json");
const bot = require("discord.js");
const client = new bot.Client({disableEveryone: true});
bot.on("ready", async() => {
console.log(`Bot is ready!${bot.user.username}`);
try{
let link = await bot.generateInvite(["ADMINISTRATOR"]);
console.log(link);
}catch(e) {
console.log(e.stack);
}
});
bot.on("message", async message => {
if(message.author.bot) return;
if(message.channel.type === "dm") return;
let messageArray = message.content.split(" ");
let command = messageArray[0];
let args = messageArray.slice(1);
if(!command.content.startsWith(prefix)) return;
if(command == `${prefix}userinfo`) {
console.log("I'm not a moron")
}
});
bot.login(botSettings.token);
未完成
我試圖通過npm安裝discord.js所有這些方法:
npm install discord.js --save
npm install --save discord.js
npm install i --save discord.js
npm install discord.js
它似乎仍然不工作。 節點版本: V8.4.0 NPM版本:5.3.0
請幫幫忙!
不是100%確定,因爲我從來沒有使用過discordjs,但不應該是'client.on()',因爲'client'是'bot.Client'創建的實例? – ImClarky
bot只是我所做的一個常量,bot.on是discord.js的一部分。我將把const bot改爲const Discord。編輯:不工作仍然是相同的錯誤。 – Rituliant
我想你可能誤解了我......你有這樣一行:'const client = new bot.Client(...);'因此,你不應該使用'client.on(..)'? [discordjs網站上的例子](https://discord.js.org/#/)似乎暗示了這一點。 – ImClarky