【问题标题】:My discord bot is not responding even though there is no error即使没有错误,我的不和谐机器人也没有响应
【发布时间】:2022-02-24 16:53:15
【问题描述】:
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没有响应,有人知道为什么吗?

【问题讨论】:

标签: discord.js


【解决方案1】:

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

替换该行:

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

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

从官方文档可以看出:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-13
      • 2022-06-12
      • 2020-12-05
      • 2021-11-21
      • 2021-11-18
      • 2022-11-27
      • 1970-01-01
      • 2020-06-01
      相关资源
      最近更新 更多