簡體   English   中英

TypeError:bot.on不是函數

[英]TypeError: bot.on is not a function

我正在用JS做一個不和諧的機器人,無論嘗試什么,我都會不斷收到此錯誤,我已經進行了研究,似乎只是我自己得到了。

這是錯誤:

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

請幫忙!

看來您必須使用客戶端而不是Bot。 我真的不知道為什么,但是對我來說,它工作得很好。 如果您需要更多信息,請訪問https://discordapp.com/invite/bRCvFy9

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM