K
K
Kot Steamovich2020-12-02 10:39:45
Node.js
Kot Steamovich, 2020-12-02 10:39:45

Cannot read property 'run' of undefined?

I don't know what to do, I'm dumb... A friend helped me a little with the code.
Mistake:

3 command
files uploaded 1.asay.js uploaded.
2.rank.js loaded.
3.reloadbot.js is loaded.
NedoMurka124 has launched!
(node:12188) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'run' of undefined
at Client. (C:\Folders\Bot\bot.js:68:20)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Folders\Bot\node_modules\discord.js\src\client \actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Folders\Bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32 )
at WebSocketManager.handlePacket (C:\Folders\Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Folders\Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Folders\Bot\node_modules\discord.js\ src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Folders\Bot\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js :315:20)
at Receiver.receiverOnMessage (C:\Folders\Bot\node_modules\ws\lib\websocket.js:797:20)
(Use `node --trace-warnings ...` to show where the warning was created)
( node:12188) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_reje... ). (rejection id: 1)
(node:12188) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

The code:
const { err } = require('console');
const Discord = require('discord.js');
const profile = require('./uinfo.json');
const fs = require('fs');
const bot = new Discord.Client();
bot.commands = new Discord.Collection();
bot.shortcommands = new Discord.Collection();
bot.rucommands = new Discord.Collection();
let config = require('./config.json');
let token = config.token;
let prefix = config.prefix;



fs.readdir('./comms/', (err, files) => {
  if(err) console.log(err);
  let jsfiles = files.filter(f => f.split('.').pop() === 'js');
  console.log(`Загружено ${jsfiles.length} файлов команд`);
  jsfiles.forEach((f,i) => {
    let props = require(`./comms/${f}`);
    console.log(`${i+1}.${f} загружен.`);
    bot.commands.set(props.help.name,props);
    bot.shortcommands.set(props.help.shortname,props);
    bot.rucommands.set(props.help.runame,props);
  });
});

bot.on('message', async mess => {
  if(mess.author.bot) return;
  if(mess.channel.type == "dm") return;
  let uid = mess.author.id;
  if(!profile[uid]){
    profile[uid] ={
      монетки:10,
      варны:0,
      опыт:0,
      уровень:0,
      баны:0,

    };
  };
  let u = profile[uid];
  u.монетки++;
  u.опыт++;
  if(u.опыт>= (u.уровень * 5)){
    u.опыт = 0;
    u.уровень+=1;
    
    
    
  }
  fs.writeFile('./profile.json',JSON.stringify(profile),(err)=>{
    if(err) console.log(err);
  });
  bot.send = function (msg){
      mess.channel.send(msg);
  };
  let messArray = mess.content.split(" ");
  let command = messArray[0].toLowerCase();
  let args = messArray.slice(1);
  if(!mess.content.startsWith(prefix)) return;
  let cmd = bot.commands.get(command.slice(prefix.length));
  let shortcmd = bot.shortcommands.get(command.slice(prefix.length));
  let rucmd = bot.rucommands.get(command.slice(prefix.length));
  if(cmd) cmd.run(bot, mess, args);
  if(shortcmd) cmd.run(bot, mess, args);
  if(rucmd) rucmd.run(bot, mess, args);
  
});

bot.on("ready", function() {
  console.log(bot.user.username + " запустился!");
  bot.user.setActivity(`discord.gg/Тут могло быть ваше приглашение`, {type: "PLAYING"});
});



bot.login(token);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill, 2021-02-15
@Kot_Steamovich

Variables can only be declared in English. Any other languages ​​are not allowed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question