标准和要求
require('dotenv').config();
const OpenAI = require('openai-api');
// Load your key from an environment variable or secret management service
// (do not include your key directly in your code)
const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
const openai = new OpenAI(OPENAI_API_KEY);
const Discord = require('discord.js');
const TOKEN = process.env.TOKEN;
const { Client, Intents } = require('discord.js');
const bot = new Discord.Client({ intents: [Intents.FLAGS.GUILDS] });
const prefix = 'w!';
*on ready*
bot.on('ready', async() => {
console.log(`${bot.user.tag} is online!`);
bot.user.setActivity('with the code', {type: 'PLAYING'});
});
这就是问题所在,它无法检测到发送的消息--我尝试过几种不同的方法--但是没有,与我在空白服务器上测试的服务器权限没有任何关系,节点是最新的
bot.on('messageCreate', message => {
if (message.content === 'ping') {
message.channel.send('pong');
}
});发布于 2022-02-02 01:15:41
要触发messageCreate事件,必须启用DIRECT_MESSAGES客户端意图。
const bot = new Discord.Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.DIRECT_MESSAGES] });阅读更多关于意图这里的内容
https://stackoverflow.com/questions/70949426
复制相似问题