Why don't the commands in the discord bot work?

  • 0
    The code written as I can see without errors.
    But for some reason the bonus commands don't work.
    ! clear 100
    or in the code the role issuance registered on the car simply does not want to give out the role, what could be the problem ???
    I am writing in Js
    const Discord = require('discord.js');
    const bot = new Discord.Client();
    bot.commands = new Discord.Collection();
    const fs = require('fs');
    bot.mutes = require('./mutes.json');
    let config = require('./botconfig.json');
    let token = config.token;
    let prefix = config.prefix;
    let profile = require('./profile.json');
    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(`${i+1}.${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.setInterval(()=>{
            for(let i in bot.mutes){
                let time = bot.mutes[i].time;
                let guildid = bot.mutes[i].guild;
                let guild = bot.guilds.get(guildid);
                let member = guild.members.get(i);
                let muteRole = member.guild.roles.find(r => r.name === "Muted"); 
                if(!muteRole) continue;
    
                if(Date.now()>= time){
                    member.removeRole(muteRole);
                    delete bot.mutes[i];
                    fs.writeFile('./mutes.json',JSON.stringify(bot.mutes),(err)=>{
                        if(err) console.log(err);
                    });
                }
            }
    
        },5000)
    
    });
    bot.on('guildMemberAdd',(member)=>{
        let role = member.guild.roles.find(r => r.name === "Маленкий(Ballas)");
        member.addRole(role);
    });
    
    bot.on('message', async message => {
        if(message.author.bot) return;
        if(message.channel.type == "dm") return;
        let uid = message.author.id;
        bot.send = function (msg){
            message.channel.send(msg);
        };
        if(!profile[uid]){
            profile[uid] ={
                coins:10,
                warns:0,
                xp:0,
                lvl:1,
            };
        };
        let u = profile[uid];
    
        u.coins++;
        u.xp++;
    
        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 messageArray = message.content.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.rUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
        bot.uId = message.author.id;
    });
    bot.login(token);
    JavaScript Lukas Vega, Aug 2, 2019

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!