简体   繁体   中英

Discord BOT not responding at commands and no console output (discord.js)

My Discord Bot is not responding to commands, and it doesn't output to console... the only activity i see is when it prompts "Ready" on the console... but after that, no console output, no command response... I've tried eliminating or change things, I even commented out a command, but none of that worked... The code is the following

Thank you in advance

const { exception, Console } = require('console');
const Discord = require('discord.js');
const bot = new Discord.Client({ partials: ['msg', 'CHANNEL', 'REACTION'] });
const logChannel = '642465822333468676';
const { prefix, token } = require('./config.json')
const ytdl = require('ytdl-core');
bot.once('ready', () => {
    console.log('Ready!');
});

bot.login(token);
   async function getID() {
   let guild = await bot.guilds.fetch('626772371981991956');
}

bot.on('msg', msg => {

    if (msg.content === `beep`) {
        msg.channel.send('Boop. :robot:')
    }

    if (msg.content === `info`) {
        const msgInfo = new Discord.msgEmbed()
            .setTitle('Credits:')
            .setDescription('**Microsoft**\nVisual Studio Code\n**Node.js Team**\nNode.js\n**discord.js Team**\nDiscord.js')
            .addFields(
                { name: `Linguaggio e librerie`, value: `.` },
                { name: `Linguaggio:`, value: `JavaScript (Node.js)` },
                { name: `Librerie:`, value: `discord.js (NPM)` },
            )
            .addFields(
                { name: `Team Programmazione:`, value: `Programmatore:\nTeknoSenpai - Developer#5151\nTesters:\ncixy 🦎#0077\nNightmare-San#6969\nSARABASSO#5478` },
                { name: `Un grazie speciale alla comunity MadHeadz | 🔥 per aver ospitato il BOT in fase Alpha`, value: `Invito: https://discord.gg/4wSMvQj` },
            )
        msg.channel.send(msgInfo)
    }

    if (!msg.content.startsWith(prefix) || msg.author.bot) return;

    const args = msg.content.slice(prefix.length).trim().split(/ +/);
    const command = args.shift().toLowerCase();

    if (!args.length) {
        return;
        console.log("ArgsError")
    }

    //if (command === `ui`) {
    //  const uInfo = msg.mentions.member.first();
    // let userInfo = new Discord.msgEmbed()
    // .setTitle(`Informazioni Utente ${uInfo.username}`)
    // .setDescription(`Informazione Utente <@${uInfo.id}>`)
    // .addFields(
    //     { name: `Username e Tag =`, value: `${uInfo.user.username}#${uInfo.discriminator}`},
    //    { name: 'Data creazione account:', value: `${uInfo.createdAt}`},
    //  { name: 'Avatar', value: `https://cdn.discordapp.com/avatars/${uInfo.id}/${uInfo.avatar}?size=1024`},
    // )
    // .setImage(`https://cdn.discordapp.com/avatars/${uInfo.id}/${uInfo.avatar}?size=1024`)
    // .setFooter(`Bot creato da TeknoSenpai - Developer#5151`)
    // .setColor('GREEN')
    // msg.channel.send(userInfo)
    //}

    if (command === 'kick') {
        msg.mentions.member.first().kick().then((member) => {
            msg.channel.send(":wave: " + member.displayName + " è stato espulso... ordine dall'alto!");
        }).catch(() => {
            msg.channel.send(`Non puoi espellere ${taggedUser}`);
        });
        const guildOnly = true
    }
    if (command === 'ban') {
        if (msg.mentions.members.first()) {
            msg.mentions.members.first.ban().then((member) => {
                msg.channel.send(":wave: " + member.displayName + " è stato bannato... ordine dall'alto!");
            }).catch(() => {
                msg.channel.send(`Non puoi espellere ${taggedUser}`);
            });
        }
    }

    if (command === 'prune') {
        const amount = parseInt(args[0]) + 1;
        console.log("Comando eseguito correttamente")
        if (isNaN(amount)) {
            return msg.reply('Non sembra essere un numero valido...');
        } else if (amount < 1 || amount > 100) {
            return msg.reply('Devi inserire un numero tra 1 e 99.');
        }
        msg.channel.bulkDelete(amount, true).catch(err => {
            console.error(err);
            msg.channel.send('Errore durante l\'eliminazione dei messaggi');
        });
    }
})

It's not working because you are not using the correct syntax.

You need to change bot.on('msg', to bot.on('message', .

https://discordjs.guide/creating-your-bot/#listening-for-messages

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM