當使用我的一個命令更新公會檔案時,它只更新頂級公會檔案而不是它收到的公會,這里有一張圖片來進一步解釋它:

我想讓它在發送到的公會中更新,這就是我所擁有的。
代碼:
run: async (interaction, client) => {
let data = await guildSchema.findOne({
id: interaction.guild.id
});
// Command:
await guildSchema.findOneAndUpdate({
logChannel: interaction.options.getChannel("channel").id
});
}
我也試過:
await data.findOneAndUpdate({
但這只是回傳:
TypeError: data.findOneAndUpdate is not a function
uj5u.com熱心網友回復:
run: async (interaction, client) => {
const data = await guildSchema.findOneAndUpdate({
id:interaction.guild.id \\it will search for your data
},
{
logChannel: interaction.options.getChannel("channel").id
};
}
這應該適合你
uj5u.com熱心網友回復:
使用時.findOneAndUpdate(),它需要兩個引數,即過濾器和將檔案更改為的值。在您的代碼中,您基本上是在要求mongoose搜索logChannel等于等于的檔案,interaction.options.getChannel("channel").id然后您沒有指定要更新它的內容。因此,在您的情況下,您所要做的就是添加過濾器并正確接收資料,因為您使用的是.findOneAndUpdate,它會在更改之前回傳檔案快照。所以你的代碼可能看起來像這樣:
const data = await guildSchema.findOneAndUpdate({
id: interaction.guild.id // Give the filter here
},
{
logChannel: interaction.options.getChannel("channel").id // Update the data here
}, {
new: true // You can optionally give this property if you want to receive the new document after the change
});
您可以在此處了解更多資訊.findOneAndUpdate():Mongoose | findOneAndUpdate
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/475763.html
