S
S
ssurskikh2019-12-06 03:45:05
Node.js
ssurskikh, 2019-12-06 03:45:05

How to fix bug with bot.login(token);?

The bot is not starting due to some error.
The code:

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;

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(`4{I+1}/.${F} Загружен!`);
    bot.command.set(props.help.name,props);
})

bot.on('ready', () => {
 console.log(`бот готов ${bot.user.username}`)
 bot.generateInvate([ADMINISTRATOR]).then(link =>{
   console.log(link);
});

bot.on('message', msg => {
  if (msg.content === 'ping') {
    msg.reply('Pong!');
  if(Message.author.bot) return;
  if(Message.Channel.type == "dm") return;
  let user = message.author.username;
  let usetid = message.author.id;
  let messageArray = message.content.split(" ")
  let command = messageArray[0].toLoserCase();
  let args = messageArray.slice(1);
  if(message.content.startWith(prefix)) return;
  let cmd = bot.commands.get(command.slice(prefix.length));
  if(cmd) cmd.run(bot,message,args);
};
 
bot.login(token);

The compiler swears:
ожидалось "}".ts(1005) [41,18]
What's the matter?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fgvnovoross, 2019-12-17
@fgvnovoross

PHPH!!! It is logical that it does not start. In the same place, the console writes to you IN THE FACE.
logical!!!

bot.on('message', msg => {
  if (msg.content === 'ping') {

Here you have opened a normal ( and 2 curly { braces.
let cmd = bot.commands.get(command.slice(prefix.length));
  if(cmd) cmd.run(bot,message,args);
};
 
bot.login(token);

At the end, you closed one curly brace from the if.
And you did not close the curly brace and the usual one !!!
bot.on('ready', () => {
//твой код
});

Here you did the right thing! Then you opened them, and then closed them!
And don't make this mistake:
let cmd = bot.commands.get(command.slice(prefix.length));
  if(cmd) cmd.run(bot,message,args);
};
 
bot.login(token);
});

After all, if you do this, then the code will wait for the user's message to start the bot (and it will have to be launched with each new message, which will also be an error or at least a load on the system), and it will not start by itself (and therefore can't read messages either...). It would be correct to end the code like this:
let cmd = bot.commands.get(command.slice(prefix.length));
  if(cmd) cmd.run(bot,message,args);
};
 });

bot.login(token);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question