即使没有错误,我的 Discord 机器人也没有响应

My discord bot is not responding even though there is no error

const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

const config = require('./config.json');

client.once('ready', () => {
    console.log("go");
})

client.on('message', (message) => {

    if(message.content == "ping"){
        message.channel.send("pong");
    }
})

client.login(config.token);

代码没有错误,但是当我输入 ping 时,bot 没有响应,有人知道为什么吗?

这是因为您没有启用 GUILD_MESSAGES 意图!

替换该行:

const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

const client = new Client({ intents: [Intents.FLAGS.GUILDS,Intents.FLAGS.GUILD_MESSAGES] });

从官方文档可以看出:

GUILD_MESSAGES 意图让我们有事件,其中之一是 MESSAGE_CREATE(在创建(发送)消息时发出)

自从 discord.js 的新更新后,提供意图是 Disocrd 机器人不可或缺的一部分。


    const {Client, Intents, Collection} = require('discord.js')
    const client = new Client({intents:[Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]})