I'm making a discord bot in JS and I keep getting this error no matter what I try, I've researched and it seems it's just me getting it.
This is the error:
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
This is the batch startup code for my bot:
node bot.js
pause
This is the javascript code for my bot:
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);
Unfinished
I've tried to install discord.js via npm all of these ways:
npm install discord.js --save
npm install --save discord.js
npm install i --save discord.js
npm install discord.js
it still doesn't seem to work. node version: v8.4.0 npm version: 5.3.0
Please help!
It seems like you have to use client instead of bot. I really don't know why, but for me it worked perfectly fine. If you need more information go on https://discordapp.com/invite/bRCvFy9
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.