这是我的代码:

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
  apiKey: client.config.openai,
});
const openai = new OpenAIApi(configuration);

client.on("messageCreate", async (message) => {
  if (message.author.bot) return;
  if (message.content.startsWith("!")) return;
  if (message.channel.type !== ChannelType.DM) return;

  let conversationLog = [
    { role: "system", content: "Hello, how can I help you?" },
  ];

  conversationLog.push({
    role: "user",
    content: message.content,
  });

  await message.channel.sendTyping();

  const result = await openai.createChatCompletion({
    model: "gpt-3.5-turbo",
    messages: conversationLog,
  });

  message.reply(result.data.choices[0].message);
});

这就是我的问题,我试图创建一个聊天机器人,它将只响应DM-而不是任何其他渠道/公会,但它失败了!当我转到ChannelType.DMChannelType.GuildText,在文本频道聊天时,它会回应!我该怎么办?顺便说一句,我的意图是:

const {
  Guilds,
  GuildMembers,
  GuildMessages,
  MessageContent,
  DirectMessages,
  GuildVoiceStates,
} = GatewayIntentBits;

以下是我的Partials:

const { User, Message, GuildMember, ThreadMember } = Partials;

任何答案都可以接受!

注:

Thisthis的答案似乎不起作用!

推荐答案

DM通道可以取消缓存,因此您还需要添加Channel个分音:

const { GatewayIntentBits, Partials } = require('discord.js');

const client = new Discord.Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.MessageContent,
    // ...
  ],
  partials: [Partials.Channel, Partials.Message],
});

Javascript相关问答推荐

除了在Angular 16中使用快照之外,什么是可行且更灵活的替代方案?

传递一个大对象以在Express布局中呈现

TypeScript索引签名模板限制

为什么promise对js中的错误有一个奇怪的优先级?

屏幕右侧屏障上的产卵点""

Reaction Native中的范围滑块

正则表达式,允许我匹配除已定义的子字符串之外的所有内容

如何在.NET Core中将chtml文件链接到Java脚本文件?

如何在FastAPI中为通过file:/URL加载的本地HTML文件启用CORS?

<;img>;标记无法呈现图像

JavaScript:如果字符串不是A或B,则

如何组合Multer上传?

使用Reaction窗体挂钩注册日历组件

Reaction即使在重新呈现后也会在方法内部保留局部值

为什么NULL不能在构造函数的.Prototype中工作

如何在Reaction中清除输入字段

ComponentWillReceiveProps仍在React 18.2.0中工作

如何将对象推送到firestore数组?

使用Java脚本替换字符串中的小文本格式hashtag

我如何才能让p5.js在不使用实例模式的情况下工作?