Discord.js无法识别嵌入的描述



我一直在为我所在的服务器制作自定义bot,一切都很顺利,直到我在代码中遇到这个运行时错误,这个代码似乎工作得很好。任何建议吗?

错误:

throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Invalid Form Body
embeds[0].description: This field is required
at RequestHandler.execute (C:Usersarinbnode_modulesdiscord.jssrcrestRequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:Usersarinbnode_modulesdiscord.jssrcrestRequestHandler.js:51:14)
at async TextChannel.send (C:Usersarinbnode_modulesdiscord.jssrcstructuresinterfacesTextBasedChannel.js:175:15) {
method: 'post',
path: '/channels/949653134551154718/messages',
code: 50035,
httpStatus: 400,
requestData: {
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [
{
title: null,
type: 'rich',
description: null,
url: null,
timestamp: null,
color: null,
fields: [],
thumbnail: null,
image: null,
author: null,
footer: null
}
],
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}

代码:

client.on('interactionCreate', (interaction) => {
let target = client.channels.cache.get(baseChannel) // gets channel 'general'
let waitTrue = setWaitTime()
if (!waitTrue) {
console.log("sending success message")
await interaction.reply({embeds: [
new MessageEmbed()
.setColor("DARK_BUT_NOT_BLACK")
.setTitle("Current Status")
.setDescription("OFF")              
]})
target.send({components: [defaultMessage(serverState)] })
} else {
interaction.reply({embeds : [waitTrue]})
}
}

function setWaitTime() {
state = serverState
let retValue = false
if (state.minecraft.players + state.hlServer.players != 0 ){
retValue = {embeds: [
new MessageEmbed()
.setColor("LUMINOUS_VIVID_PINK")
.setDescription(`People are currently using the ${(state.minecraft.on) ? "minecraft": (state.hlServer.on) ? "TF2" : "ERROR"} server, try again later`)
.setTitle("Queued your selection")
]
}           
}
console.log(retValue)
return retValue

我不知道为什么discord.js没有识别已应用于嵌入的。setdescription(…),特别是因为这个函数没有改变,因为它工作…

执行setWaitTime()函数后,retValue变量的值是一个具有embed键的对象,值是MessageEmbed,所以当您尝试发送retValue时,实际发生的情况是这样的:

interaction.reply({
embeds: {
embeds: {
new MessageEmbed()
// ...
}
}
})

这就是为什么会发生这个特定的错误。为了解决这个问题,我们不把retValue作为嵌入属性发送,而是自己发送,像这样:

interaction.reply(retValue)

最新更新