【发布时间】:2021-02-13 16:27:09
【问题描述】:
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..```
【问题讨论】:
-
您检查过
warnInfo是什么吗?它是可迭代的吗?
标签: javascript node.js discord.js node-sqlite3 quick.db