簡體   English   中英

如何將帶有按鈕的嵌入發送到 discord.js 中的特定頻道?

[英]How do I send an embed with buttons to a specific channel in discord.js?

因此,我正在嘗試將嵌入發送到特定頻道 ( 1068005047373414481 ),並且我想使用ActionRow組件發送帶有某種新按鈕的嵌入。 請記住,該頻道與運行交互的頻道不同。 無論如何,我已經嘗試使用interaction.guild.channels.cache.get(id).send(embed); 方法,但似乎不起作用。 我總是以DiscordAPIError[50006]: Cannot send an empty message錯誤告終。 無論哪種方式,我都不認為您可以像使用interaction.reply({ embeds: embed, components: [row] });那樣向該消息添加組件。

這是我當前的代碼:

client.once('ready', () => {
    console.log('Ready!')
    client.user.setActivity("all you rascals", {
        type: ActivityType.Watching,
    });
    var testing = new EmbedBuilder()
    .setTitle('test')

    client.guilds.cache.get(guild).channels.cache.get(channel).send(testing)
})

(這是為了測試,因為一旦找到答案,我將在我的機器人中實施正確的方法)

當我運行它時,出現此錯誤:

C:\Users\User\OneDrive\Documents\a\c\fbot\node_modules\@discordjs\rest\dist\lib\handlers\SequentialHandler.cjs:293
        throw new DiscordAPIError.DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
              ^

DiscordAPIError[50006]: Cannot send an empty message
    at SequentialHandler.runRequest (C:\Users\User\OneDrive\Documents\a\c\fbot\node_modules\@discordjs\rest\dist\lib\handlers\SequentialHandler.cjs:293:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async SequentialHandler.queueRequest (C:\Users\User\OneDrive\Documents\a\c\fbot\node_modules\@discordjs\rest\dist\lib\handlers\SequentialHandler.cjs:99:14)
    at async REST.request (C:\Users\User\OneDrive\Documents\a\c\fbot\node_modules\@discordjs\rest\dist\lib\REST.cjs:52:22)
    at async TextChannel.send (C:\Users\User\OneDrive\Documents\a\c\fbot\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:175:15) {
  rawError: { message: 'Cannot send an empty message', code: 50006 },
  code: 50006,
  status: 400,
  method: 'POST',
  url: 'https://discord.com/api/v10/channels/1068005047373414481/messages',
  requestBody: {
    files: [],
    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
    }
  }
}
interaction.reply({ embeds: embed, components: [row] });

非常接近您的需要,記住 embeds 屬性必須是一組嵌入,即使您只有一個。

正確的代碼是

interaction.reply({ embeds: [embed], components: [row] });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM