0

quick.db 出现错误

我试图制作一个 view-case 命令来查看用户惩罚的详细信息等等。但我得到一个错误说warnInfo is not iterable有人可以帮助我

const Discord = require("discord.js");
const database = require("quick.db");
const config = require('../config.json');

module.exports = {
    name: "view-case",
    description: "View details of a user's punishment / warnings.",
    async execute(message, args) {
    const warnInfo = database.get(`info.${message.author.id}.${message.guild.id}`)

    if(!args.length) {
// invalid usage returns
    };

    for(let warnings of warnInfo){
        let mod = warnings.moderator
        let reason = warnings.reason
        let date = warnings.date
        let cases = warnings.cases
        let numbercase = warnings.numbercase
        let dur = warnings.duration
    
        if(args[0] === numbercase) {
            let embed = new Discord.MessageEmbed()
            .setAuthor(message.author.tag, message.author.displayAvatarURL({ dynamic: true }))
            .setTitle(`Case #${numbercase}`)
            .setDescription(`**Case**: ${cases} \n**Moderator**: ${mod} \n**Reason**: ${reason} \n**Date**: ${date} \n**Mute Duration**: ${dur}`)
            .setColor("RANDOM")
            .setTimestamp();
            return message.channel.send(embed)
        }
    }
    }
}

错误日志

(node:3308) UnhandledPromiseRejectionWarning: TypeError: warnInfo is not iterable
    at Object.execute (C:\Users\DS9\Documents\GitHub\sarah\commands\view-case.js:29:25)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:3308) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:3308) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with
a non-zero exit code..```
4

1 回答 1

0

通常,当您访问不是“类似数组”的“事物”时会出现该错误,但这很明显。出于调试原因,只需在此行之后添加 aconsole.log(warnInfo)或 a : .debuggerconst warnInfo = database.get(`info.${message.author.id}.${message.guild.id}`)

这样,您将看到 db 发送回给您的值的类型,并且您将能够调整代码以正确读取它。

我还看到您将execute函数用作async function,但我在该代码块中看不到任何等待或承诺。可能也值得修复它。

于 2020-10-31T12:02:59.243 回答