提问人:GodSoda 提问时间:11/12/2023 更新时间:11/12/2023 访问量:28
(Discord v14) discord bot 不回复消息 pong [duplicate]
(Discord v14) discord bot doesn't replies the message pong [duplicate]
问:
我正在制作一个简单的 discord 机器人,它回复某些消息,例如某些用户说“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]**
答:
-1赞
Darshan B
11/12/2023
#1
MessageContent
意图
机器人需要查看和回复消息的意图。MessageContent
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent // add this
]
});
特权意向
此外,在开发人员门户上启用以下意向
评论