我正在制作一个简单的不和谐机器人,它会回复某些消息,例如某些用户说“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]**
MessageContent
意图您的机器人需要
MessageContent
意图来查看和回复消息。
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent // add this
]
});
还可以在开发者门户
上启用以下意图