Опять ошибка с ботом :TypeError: Cannot read property 'name' of undefined
bot.js(index.js)
const Discord = require('discord.js');
const robot = new Discord.Client();
const ytdl = require('ytdl-core');
const fs = require('fs');
const request = require('request');
const getYoutubeID = require('get-youtube-id');
const fetchVideoInfo = require('youtube-info');
const BotSettings = require("./botsettings.json");
const prefix = BotSettings.prefix;
robot.login(ТУТ ТОКЕН);
robot.commands = new Discord.Collection();
fs.readdir("./cmds/",(err,files) => {
if(err) console.error(err);
let jsfiles = files.filter(f => f.split(".").pop() === "js");
if(jsfiles.length <= 0){
console.log("No commands to load");
return;
}
console.log(`Loading ${jsfiles.length} commands!`);
jsfiles.forEach((f,i) => {
let props = require(`./cmds/${f}`);
console.log(`${i + 1}: ${f} loaded!`);
robot.commands.set(props.help.name, props);
});
});
robot.on('ready', (message) =>{
console.log(`Bot is ready! ${robot.user.username}`);
console.log(robot.commands);
});
robot.on('message', async (message) => {
if(message.author.bot) return;
let messageArray = message.content.split(" ");
let command = messageArray[0];
let args = messageArray.slice(1);
if(!command.startsWith(prefix)) return;
let cmd = robot.commands.get(command.slice(prefix.length));
if(cmd) cmd.run(robot,message, args);
});
/cmds/userinfo.js
module.exports.run = async (bot, message, args) => {
if(message.author.username === 'Mrsasha45op'){
let embed = new Discord.RichEmbed().setAuthor(message.author.username).setDescription("Топовый админ");
message.channel.sendEmbed(embed);
}else{
if(message.author.username === `Фиолетовая Мангл`){
let embed = new Discord.RichEmbed().setAuthor(message.author.username).setDescription("Я умею рисовать");
message.channel.sendEmbed(embed);
}else{
if(message.author.username === `domber`){
let embed = new Discord.RichEmbed().setAuthor(message.author.username).setDescription("Друг и Ютубер от бога");
message.channel.sendEmbed(embed);
}else {
let embed = new Discord.RichEmbed().setAuthor(message.author.username).setDescription("Хороший пользователь");
message.channel.sendEmbed(embed);
}
}
}
module.exports.help = {
name: "userinfo"
}}
Судя по всему, ошибка у вас тут: robot.commands.set(props.help.name, props);
?
Текст ошибки говорит о том, что props.help
возвращает undefined
.
Проверьте содержимое вашего файла ./cmds/${f}
, есть ли у него поле help
(скорее всего нет).
Кофе для программистов: как напиток влияет на продуктивность кодеров?
Рекламные вывески: как привлечь внимание и увеличить продажи
Стратегії та тренди в SMM - Технології, що формують майбутнє сьогодні
Выделенный сервер, что это, для чего нужен и какие характеристики важны?
Современные решения для бизнеса: как облачные и виртуальные технологии меняют рынок