0

我目前正在尝试更新 mongoDb 中的文档。我是 mongo 的新手,阅读文档对我没有任何帮助 + 我没有收到任何错误

我的代码

const Guild = require('../schemas/GuildSchema')

module.exports = {
    name: 'whitelist',
    description: "whitelist",
    async execute(bot, message, args, PREFIX, Discord, settings, fs) {

        if (message.author.id != "173347297181040640") {
            return message.channel.send("Sorry only Bacio001 can whitelist!")
        }

        if (!args[1]) {
            return message.channel.send("No guild id given!")
        }

        try {

            Guild.findOneAndUpdate(
                { guildid: args[1]},
                { $set: { whitelisted : true } }
            )

        } catch (e) {

            console.log(e);

        }

        let guild = bot.guilds.cache.get(args[1]);

        message.channel.send(`Whitelisted ${guild.id} with the name ${guild.name} !`)
        
    }
}

https://gyazo.com/a58a9d8175a8a38674b32a2776fa48cb

4

1 回答 1

0

所以我最终发现了我必须等待 Guild.findOneAndUpdate 的问题

const Guild = require('../schemas/GuildSchema')

module.exports = {
    name: 'whitelist',
    description: "whitelist",
    async execute(bot, message, args, PREFIX, Discord, settings, fs) {

        if (message.author.id != "173347297181040640") {
            return message.channel.send("Sorry only Bacio001 can whitelist!")
        }

        if (!args[1]) {
            return message.channel.send("No guild id given!")
        }

        try {

            await Guild.findOneAndUpdate(
                { guildid: args[1]},
                { whitelisted : true }
            )

        } catch (e) {

            console.log(e);

        }

        let guild = bot.guilds.cache.get(args[1]);

        message.channel.send(`Whitelisted ${guild.id} with the name ${guild.name} !`)
        
    }
}
于 2021-05-13T02:24:52.927 回答