Answer the question
In order to leave comments, you need to log in
Why does the bot not accept commands?
bot discord
const Discord = require('discord.js');
const fs = require('fs');
const bot = new Discord.Client();
let config = require('./botconfig.json');
let token = config.token;
let prefix = config.prefix;
let profile = require('./profile.json');
bot.commands = new Discord.Collection();
fs.readdir('./cmds', (err, files) =>{
if (err) console.log(err);
let jsfile = files.filter(f => f.split('.').pop() === 'js');
if (jsfile.length <= 0) return console.log('Комманды не найдены!');
console.log(`Loaded ${jsfile.length} commands`);
jsfile.forEach((f, i) => {
let props = require(`./cmds/${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('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 +=0.25;
u.xp +=0.35;
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 user = message.author.username;
let userid = message.author.id;
let messageArray = message.cotent.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);
the bot code itself why the bot does not read messages find my mistake
Answer the question
In order to leave comments, you need to log in
I can say that I did not see the message check.
for example:
You have:
if(!profile[uid]){
profile[uid] ={
coins:10,
warns:0,
xp:0,
lvl:0,
};
if(message.content.toLowerCase()==="!profile[uid]"){
profile[uid] ={
coins:10,
warns:0,
xp:0,
lvl:0,
};
if(message.content.toLowerCase()==="!profile"){
let mbr = message.mentions.members.first() || message.member;
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question