简体   繁体   English

Bot 在线,但前缀和命令不起作用

[英]Bot is online but the prefix and commands don't work

When I try to put the prefix with the command the bot doesn't respond.当我尝试将前缀与命令放在一起时,机器人没有响应。

code:代码:

const { Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, Permsision } = require('discord.js');

const prefix ='>';

const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });

client.on('ready', () => {
    console.log('Bot has come online.')
})
 
client.on('message', message => {
 
    let args = message.content.substring(PREFIX.length).split(' ')
 
    switch(args[0]){
        case 'mc':
 
            if(!args[1]) return message.channel.send('You must type a minecraft server ip')
            if(!args[2]) return message.channel.send('You must type a minecraft server port')
 
            ping(args[1], parseInt(args[2]), (error, reponse) =>{
                if(error) throw error
                const Embed = new RichEmbed()
                .setTitle('Server Status')
                .addField('Server IP', reponse.host)
                .addField('Server Version', reponse.version)
                .addField('Online Players', reponse.onlinePlayers)
                .addField('Max Players', reponse.maxPlayers)
                
                message.channel.send(Embed)
            })
        
 
    }
 
})

I expected it to respond to me when I did the command, it showed in the console the bot was ready我希望它在我执行命令时响应我,它在控制台中显示机器人已准备就绪
and I searched about it and it said I needed intent and I think I have it.我搜索了一下,它说我需要意图,我想我已经有了。

As Zsolt Meszaros mentioned, the message event was deprecated in Discord.JS version 13 and replaced by messageCreate in version 14.正如Zsolt Meszaros提到的, message事件在 Discord.JS 版本 13 中被弃用,并在版本 14 中被messageCreate取代。

const { Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, Permsision } = require('discord.js');

const prefix = '>';

const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });

client.on('ready', () => {
    console.log('Bot has come online.');
});

client.on('message', (message) => {
    let args = message.content.substring(PREFIX.length).split(' ');

    switch (args[0]) {
        case 'mc':
            if (!args[1]) return message.channel.send('You must type a minecraft server ip');
            if (!args[2]) return message.channel.send('You must type a minecraft server port');

            ping(args[1], parseInt(args[2]), (error, reponse) => {
                if (error) throw error;
                const Embed = new RichEmbed()
                    .setTitle('Server Status')
                    .addField('Server IP', reponse.host)
                    .addField('Server Version', reponse.version)
                    .addField('Online Players', reponse.onlinePlayers)
                    .addField('Max Players', reponse.maxPlayers);

                message.channel.send(Embed);
            });
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Heroku 部署了我的 discord 机器人,但它的命令不起作用 - Heroku deploys my discord bot, but the it's commands don't work 我的 Discord.js bot 正在运行(在线并显示在控制台中)但它不会响应命令 - My Discord.js bot is running (online and shows in console) but it won't respond to commands 我的href链接按钮无法在线使用 - My href link buttons don't work online js中的响应式Toggle菜单(用于移动设备)可在本地使用,但不能在线使用 - Responsive Toggle menu (for mobile) in js work on local but don't work online 我的机器人不和谐不起作用。 我不知道为什么 - My bot discord doesn't work. I don't know why 这是什么类型的 JavaScript 混淆,我怎样才能正确地去混淆它? (在线反混淆器不起作用) - What type of JavaScript obfuscation is this and how can I properly deobfuscte it? (online deobfuscators don't work) pm 2 启动我的机器人,但机器人不在线 - pm 2 starts my bot, but the bot isn't online on discord 一些 discord bot 命令别名有效,而有些则无效,没有收到任何错误? - some discord bot command aliases work and some don't, not getting any errors? Discord 机器人不会回答命令 - Discord bot won't answer commands 不明白接受前缀作为参数 - don't understand accepting prefix as an argument
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM