MongooseError:查询已执行:错误:Discord.js



代码

const fetch = require("node-fetch");

client.on('messageCreate', async (message) => {
const chatbots = require("./All-Commands-Schemas/ChatbotSchema")
await 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 === 'dm') return;
if (message.channel.id === channell) {
message.channel.sendTyping();
await fetch(`http://api.brainshop.ai/get?bid=163&key=rztKzYO&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!");
})
};
});
});

错误

Reason: MongooseError: Query was already executed: chatbots.findOne(

嗨,我需要帮助解决上面提供的以下错误和代码。以下是我的代码版本。

"猫鼬":"6.1.6";,"discord.js":"13.3.1";,"节点":"16.13.2";,"npm":"8.1.2";

您不能在同一查询中使用等待和回调,您应该删除等待

chatbots.findOne({ guild: message.guild.id }, async (err, data) => {
//do some thing
}

或回调

const data = awaitchatbots.findOne({ guild: message.guild.id })
//do something

相关内容

  • 没有找到相关文章

最新更新