【问题标题】:Copied Embed returning empty复制的嵌入返回空
【发布时间】:2021-08-10 20:58:02
【问题描述】:

所以基本上,我正在尝试从 1 个频道获取嵌入,然后将其发送到另一个频道,但它给出了一个错误,说明有关空消息的内容。

完全错误:

Received 1 messages
/home/bot/node_modules/discord.js/src/rest/RequestHandler.js:298
      throw new DiscordAPIError(data, res.status, request);
            ^

DiscordAPIError: Cannot send an empty message
    at RequestHandler.execute (/home/bot/node_modules/discord.js/src/rest/RequestHandler.js:298:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (/home/bot/node_modules/discord.js/src/rest/RequestHandler.js:50:14)
    at async TextChannel.send (/home/bot/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:171:15) {
  method: 'post',
  path: '/channels/874619472902774845/messages',
  code: 50006,
  httpStatus: 400,
  requestData: {
    json: {
      content: undefined,
      tts: false,
      nonce: undefined,
      embeds: undefined,
      components: undefined,
      username: undefined,
      avatar_url: undefined,
      allowed_mentions: undefined,
      flags: undefined,
      message_reference: undefined,
      attachments: undefined,
      sticker_ids: undefined
    },
    files: []
  }
}

这是我的机器人脚本:

const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });;

client.on('ready', () => {
const channel1 = client.channels.cache.get("791100523246911499");
const logchannel1 = client.channels.cache.get("874619472902774845");


channel1.messages.fetch({ limit: 1 }).then(messages => {
    console.log(`Received ${messages.size} messages`);
    //Iterate through the messages here with the variable "messages".
    messages.forEach(message => {
        logchannel1.send(message.embeds);
    })
  })

我希望了解 discord.js 的人可以帮助我解决这个难题。

感谢阅读 问候,臭名昭著。

【问题讨论】:

    标签: discord discord.js


    【解决方案1】:

    这部分不正确

    messages.forEach(message => {
            logchannel1.send(message.embeds);
        })
    

    您必须指定它们是嵌入的

    messages.forEach(message => {
            logchannel1.send('optional content', {embeds: [...message.embeds]});
        })
    

    【讨论】:

    • 如果我想在不和谐的 webhook 中传递 message.embeds 该怎么办
    • 完全一样的方式,但不是“可选内容”,而是将其删除,并替换为{content: 'optional content', embeds: [...message.embeds]}
    • 我试过了,hook1.send({embeds: [...message.embeds]});它给了我一个错误。 (node:19416) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'username' of undefined at /home/stealer/node_modules/webhook-discord/lib/webhook.js:296:38 at new Promise () at Webhook.send (/home/stealer/node_modules/webhook-discord/lib/webhook.js:294:16) 在 Client. (/home/stealer/index.js:46:15) 在 Client.emit (events.js :314:20)
    • 我也尝试过这样做:webhookClient.send({ content: 'Logs', username: 'Logs', embeds: [message.embeds], }) 这给了我错误 405 方法不允许跨度>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-27
    相关资源
    最近更新 更多