【发布时间】:2022-12-23 03:30:01
【问题描述】:
请帮我。这是我下面关于 discord.js 聊天机器人的代码
const fetch = require("node-fetch");
const {ChannelType} = require("discord.js");
client.on('messageCreate', async (message) => {
const chatbots = require("./All-Commands-Schemas/ChatbotSchema")
chatbots.findOne({ guild: message.guild.id }, async (err, data) => {
if (!data) return;
if (err) throw err
const channell = data.channel;
if (message.author.bot || message.channel.type === ChannelType.DM) return;
if (message.channel.id === channell) {
message.channel.sendTyping();
await fetch(`http://api.brainshop.ai/get?bid=164279&key=rhBjCAZC83ztKzYO&uid=${message.author.id}&msg=${message.content}`)
.then(cnt => cnt.json())
.then(data => {
message.channel.send(data.cnt);
})
.catch(() => {
message.channel.send("Couldn't fetch response!");
})
}
})
})
聊天机器人架构
const mongoose = require("mongoose");
const chatbots = new mongoose.Schema({
guild: String,
channel: String,
name: String
});
module.exports = mongoose.model("chatbots", chatbots);
问题是聊天机器人不回复或在控制台日志中显示错误。我已经尝试了一切。
“节点获取”:“^3.3.0”, "discord.js": "^14.6.0", “猫鼬”:“^6.7.0”
【问题讨论】:
-
您是否启用了消息内容意图并在创建客户端时指定了它?
标签: mongoose discord.js