(Discord v14)discord 机器人不回复消息 pong

问题描述 投票:0回答:1

我正在制作一个简单的不和谐机器人,它会回复某些消息,例如某些用户说“ping”,而不是机器人回复消息“pong”,所以这是源代码

const { Client, Events, GatewayIntentBits, Message } = require('discord.js');
const { token } = require('./config.json');

// Create a new client instance
const client = new Client({ intents: [GatewayIntentBits.Guilds,GatewayIntentBits.GuildMessages] });

// When the client is ready, run this code (only once)
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
client.once(Events.ClientReady, c => {
    console.log(`Ready! Logged in as ${c.user.tag}`);
});
//client.on("debug", console.log)

client.on('messageCreate', (message => {
    if (message.content === 'ping') {
        message.reply('pong')
    }
}))

client.on('error', console.error);

// Log in to Discord with your client's token
client.login(token);```

when I tested I said ping on the discord chat but the bot didn't replied. I gave the bot admin permission so there should not be a permission problem can anybody give me some answer about this problem?
the version of discord.js is **[email protected]**
node.js discord discord.js message
1个回答
0
投票

MessageContent
意图

您的机器人需要

MessageContent
意图来查看和回复消息。

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

特权意图

还可以在开发者门户

上启用以下意图

© www.soinside.com 2019 - 2024. All rights reserved.