[英]How do I fix my discord bot (in discord.js) not responding to my commands
[英]My discord bot code is working but is not responding to my commands
我是编程的大三学生。 我知道 node.js 并想为不和谐编写自己的机器人。
下面写的我的代码不起作用。 你能帮我解决这个问题吗?
const { Client, Intents } = require('discord.js');
const config = require('./config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message=>{
if(!message.content.startsWith(config.prefix) || message.author.bot) return;
const args = message.content.slice(config.prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong!');
}
})
client.login(config.token);
GUILDS
意图不足以接收消息。 您还需要GUILD_MESSAGES
消息意图:
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
})
我还没有看到您的错误消息,但我认为这是因为您的意图,所以非常简单的解决方案是:
const client = new Client({
intents: 32767
});
但是您还需要在https://discord.com/developers 的机器人设置中启用所有意图
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.