我该怎么做才能让我的机器人说些什么



所以我的代码就是这样的,我想做一些事情,说"pong";当我们说";ping";。我不明白为什么它不起作用,我是个乞丐,ty!

require('dotenv').config();
const { Client, GatewayIntentBits } = require('discord.js')
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
]
})
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('pong');
}
});
client.login(process.env.DISCORD_TOKEN);

您需要将GatewayIntentBits.GuildMessages添加到您的意图中

require('dotenv').config();
const { Client, GatewayIntentBits } = require('discord.js')
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages
]
})
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('pong');
}
});
client.login(process.env.DISCORD_TOKEN);

此外,您还需要启用消息内容意图但我建议你切换到斜杠命令

相关内容

最新更新