Discord BOT对命令无响应并且没有控制台输出(discord.js)

时间:2020-11-08 15:31:46

标签: javascript node.js discord discord.js

我的Discord Bot没有响应命令,也没有输出到控制台...我看到的唯一活动是当它在控制台上提示“ Ready”时...但是此后,没有控制台输出,没有命令响应...我试图消除或更改某些内容,甚至注释掉一条命令,但这些命令均无效...代码如下

提前谢谢

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');
        });
    }
})

1 个答案:

答案 0 :(得分:0)

它不起作用,因为您使用的语法不正确。

您需要将<!-- Modal --> <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Enter New Rank</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span> </button> </div> <div class="modal-body"> <form action="{% url 'mainapp:home' %}" method="post"> {% csrf_token %} {{ form.new_rank }} <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button class="btn btn-primary" type="submit">Change Rank</button> </form> </div> <!-- <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Send message</button> </div> --> </div> </div> </div> <!-- Modal --> <div class="modal fade" id="exampleModal_comment" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel_comment" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel_comment">Add Comment </h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span> </button> </div> <div class="modal-body"> <form action="{% url 'mainapp:home' %}" method="post"> {% csrf_token %} {{ form.comment }} <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button class="btn btn-primary" type="submit">Add Comment</button> </form> </div> <!-- <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Send message</button> </div> --> </div> </div> </div> <script type="text/javascript"> $('#exampleModal').on('show.bs.modal', function(event) { var button = $(event.relatedTarget) // Button that triggered the modal var recipient = button.data('whatever') // Extract info from data-* attributes // If necessary, you could initiate an AJAX request here (and then do the updating in a callback). // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead. var modal = $(this) // modal.find('.modal-title').text('New message to ' + recipient) modal.find('.modal-title').text('Enter New Rank - Old rank was ' + recipient) modal.find('.modal-body input').val(recipient) }) $('#exampleModal_comment').on('show.bs.modal', function(event) { var button = $(event.relatedTarget) // Button that triggered the modal var recipient = button.data('whatever') // Extract info from data-* attributes // If necessary, you could initiate an AJAX request here (and then do the updating in a callback). // Update the modal's content. We'll use jQuery here, but you could use a data binding library or other methods instead. var modal = $(this) // modal.find('.modal-title').text('New message to ' + recipient) modal.find('.modal-title').text('Add New Comment') modal.find('.modal-body input').val(recipient) }) </script> 更改为bot.on('msg',

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