Discord.js-DiscordAPI错误:嵌入的表单正文无效.fields[0].值:此字段是必需的.错误



我一直在尝试为我的discord.js机器人制作一个订单命令,当有人使用该命令时,它没有响应,并在控制台中说了这个错误"此错误源于在没有catch块的异步函数内部抛出,或是拒绝了未使用.catch((处理的promise。promise被拒绝的原因如下:DiscordAPIError:表单正文无效embed.fields[0].value:此字段是必需的"然而,我一直在尝试修复它,但我看不出代码有什么问题,命令的代码是

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.");
}
});
});
};```

欢迎使用StackOverflow!它只是意味着在fields[0]中没有value。试试这个:

fields: [{
name: "Order Description",
value: order || "None", // Returns None if no order
}, {
name: "Order ID",
value: ticketID,
}, {
name: "Order Status",
value: ticketID",
}],

一个更好的解决方案是检查所有需要的变量是否都是您所期望的。例如,您可以在代码之前添加以下内容:

if (!order) return msg.reply("No order found.");

相关内容

最新更新