【问题标题】:Discord.js does not recognise the description of an embedDiscord.js 无法识别嵌入的描述
【发布时间】:2022-06-13 23:25:46
【问题描述】:

我一直在为我所在的服务器制作一个自定义机器人,一切都很顺利,直到我在看似正常工作的代码中遇到了这个运行时错误。有什么建议吗?

错误:

throw new DiscordAPIError(data, res.status, request);
            ^

DiscordAPIError: Invalid Form Body
embeds[0].description: This field is required
    at RequestHandler.execute (C:\Users\arinb\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (C:\Users\arinb\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
    at async TextChannel.send (C:\Users\arinb\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.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(...),尤其是因为此函数自工作以来并未更改...

【问题讨论】:

    标签: discord.js


    【解决方案1】:

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

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

    这就是发生此特定错误的原因。所以要修复它,而不是发送 retValue 作为嵌入属性,只需像这样发送它自己:

    interaction.reply(retValue)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-20
      • 1970-01-01
      • 2020-02-19
      相关资源
      最近更新 更多