我一直在尝试为我的 discord.js 机器人创建一个命令命令,当有人使用它没有响应的命令并在控制台中显示此错误“此错误源于在没有 catch 块的情况下抛出异步函数内部,或者通过拒绝未使用 .catch() 处理的承诺。承诺被拒绝的原因是:DiscordAPIError: Invalid Form Body embed.fields[0].value: This field is required" 但是我一直在尝试修复它,但我看不到命令代码的代码有什么问题
const colors = require("colors");
function generateID() {
let ticketGen = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split("");
let ticketStr = "";
for(let i = 0; i < 3; i++) {
ticketStr += ticketGen[Math.floor(Math.random() * ticketGen.length)];
}
return ticketStr;
}
exports.id = "order";
exports.onLoad = api => {
api.commands.add("order", (msg) => {
// The order.
let order = msg.content.substring(8);
let customer = msg.author.id
fsn.readJSON("./blacklist.json").then((blacklistDB) => {
let entry = blacklistDB[msg.guild.id];
// Checks is server is blacklisted or not.
if(entry === undefined) {
// Gets ticket ID.
const ticketID = generateID();
// Sends ticket information to tickets channel.
api.client.guilds.get("745409671430668389").channels.get("746423099871985755").send({embed: {
color: 0xFFFFFF,
title: msg.author.username,
fields: [{
name: "Order Description",
value: order,
}, {
name: "Order ID",
value: ticketID,
}, {
name: "Order Status",
value: ticketID,
}],
timestamp: new Date(),
footer: {
text: `From ${msg.guild} (${msg.guild.id})`
}
}}).then((m) => {
m = m.id;
// Sets ticket info.
fsn.readJSON("./orders.json").then(orderDB => {
// Set JSON information.
if (!orderDB[ticketID]) orderDB[ticketID] = {
"orderID": ticketID,
"userID": msg.author.id,
"guildID": msg.guild.id,
"channelID": msg.channel.id,
"order": order,
"status": "Unclaimed",
"ticketChannelMessageID": m
};
// Write JSON information.
fsn.writeJSON("./orders.json", orderDB, {
replacer: null,
spaces: 4
}).then(() => {
// Sends an embed to the customer.
msg.channel.send("Thanks for ordering! Your order will be delivered soon, Order ID: `\`${ticketID}\``");
// Logs in console.
console.log(colors.green(`${msg.author.username} ordered "${order}" in ${msg.guild.name} (${msg.guild.id}) in ${msg.channel.name} (${msg.channel.id}).`));
}).catch((err) => {
if(err) {
msg.reply(`There was a database error! Show the following message to a developer: \`\`\`${err}\`\`\``);
console.log(colors.red(`Error in order ${ticketID}: ${err}`));
}
});
});
});
}else {
msg.reply("This server is currently blacklisted.");
}
});
});
};```