Я не знаю что делать, я тупенький... С кодом немного помог друг.
Ошибка:
Загружено 3 файлов команд
1.asay.js загружен.
2.rank.js загружен.
3.reloadbot.js загружен.
НедоМурка124 запустился!
(node:12188) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'run' of undefined
at Client. (C:\Папки\Bot\bot.js:68:20)
at Client.emit (events.js:315:20)
at MessageCreateAction.handle (C:\Папки\Bot\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (C:\Папки\Bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (C:\Папки\Bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:384:31)
at WebSocketShard.onPacket (C:\Папки\Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:444:22)
at WebSocketShard.onMessage (C:\Папки\Bot\node_modules\discord.js\src\client\websocket\WebSocketShard.js:301:10)
at WebSocket.onMessage (C:\Папки\Bot\node_modules\ws\lib\event-target.js:125:16)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (C:\Папки\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.
Код:
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);