[英]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.