K
K
Kambik Zhelikhazhev2020-05-08 20:06:49
Node.js
Kambik Zhelikhazhev, 2020-05-08 20:06:49

I'm a teapot in node.js, I looked at how to make a bot for Discord, everything is identical, but it starts and I don't, and what's the problem?

Here is the code itself:

<const Discord = require('discord.js');
const bot = new Discord.Client();
bot.commands = new Discord.Collection();
const fs = require('fs');
let config = require('./botconfig.json');
let token = config.token;
let prefix = config.prefix;
let profile = require("./profile.json");



fs.readdir('./cmds/',(err,files)=>{
if(err) console.log(err);
let jsfiles = files.filter(f => f.split(".").pop() === "js");
if(jsfiles.length <=0)console.log("Нет команд для загрузки!!");
console.log(`Загружено ${jsfiles.length} команд`);
jsfiles.forEach((f,i) =>{
    let props = require(`./cmds/${f}`);
    console.log(`${i+1}.${f} Загружено!`);
    bot.commands.set(props.help.name,props);
})
});

bot.on('ready', () => {
  console.log(`Запустился бот ${bot.user.username}`);
  bot.generateInvite(["ADMINISTRATOR"]).then(link =>{
      console.log(link);
  })
});
bot.on('guildMemberAdd',(member)=>{
  try{}catch{};
  let role = member.guild.roles.find('name',"Суккуб");
  member.addRole(role);
});

bot.on('message'), async message => {
  if(message.author.bot) return;
  if(message.channel.type == "dm") return;
  let uid = message.author.id;
  if(!profile[uid]){
      profile[uid] ={
          coins:10,
          warns:0,
          Xp:0,
          lvl:0,
      };
    };

 
      

    let u = profile[uid];
    u.coins++;
    u.xp++;
    if(u.xp>= (u.lvl * 5)){
        u.xp = 0;
        u.lvl += 1;
    }
  fs.writeFile("./profile.json",JSON.stringify(profile),(err)=>{
      if(err) Console.log(err);
  });
  let profile = require("./profile.json");
  let user = message.author.username;
  let userid = message.author.id;
  let messageArray = message.content.split(" ");
  let command = messageArray[0].toLowerCase();
  let args = messageArray.slice(1);
  if(!message.content.startsWith(prefix)) return;
  let cmd = bot.commands.get(command.slice(prefix.length));
  if(cmd) cmd.run(bot,message,args);
};

bot.login(token)


I work in Visual Studio and run the bot through the TERMINAL, and it gives out this:
events.js:108
throw new ERR_INVALID_ARG_TYPE('listener', 'Function', listener);
^

TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received undefined
at checkListener (events.js:108:11)
at _addListener (events.js:343:3)
at Client.addListener (events.js:401:10)
at Object. (C:\Users\1\Desktop\TaftilkaBOT\bot.js:36:5)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal /modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)
at internal/main/run_main_module.js :18:47 {
code: 'ERR_INVALID_ARG_TYPE'


I don't understand what's wrong

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Miit, 2020-05-08
@Miit

Learn to read the log

TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received undefined

The error is here. You are not passing "listener"
bot.on('message'), async message => {

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question