generated at
ローカルの画像を埋め込みで使用するサンプル
#TODO 良いタイトル

AttachmentBuilder を使用する。
.setName(name) .setThumbnail(attachment://name) name は同じにしておく。(これは識別用?)
.setFile(attachment) attachment 内はファイルパス、Buffer、FileStreamなどが使用可能。
js
const { EmbedBuilder, AttachmentBuilder } = require("discord.js"); const embed = new EmbedBuilder().setThumbnail("attachment://thumbnail.jpg"); const attachment = new AttachmentBuilder() .setName("thumbnail.jpg") .setFile("./picture.jpg") channel.send({ files: [attachment], embeds: [embed] })

MessageEmbed attachFiles は廃止された。
attachment://<ファイル名>.<拡張子> の形式で添付したファイルにアクセスできる。
js
const buffer = //... const embed = new Discord.MessageEmbed().setThumbnail("attachment://thumbnail.jpg"); const attachment = new Discord.MessageAttachment(buffer, "thumbnail.jpg"); channel.send({ files: [attachment], embeds: [embed] });

MessageEmbed attachFiles と、 attachment:// URI Schemeを使う
attachment://<ファイル名>.<拡張子> の形式で attachFiles によって添付したファイルにアクセスできる。
> Sets the file to upload alongside the embed. This file can be accessed via attachment://fileName.extension when setting an embed image or author/footer icons. Multiple files can be attached.
正直ここに書いてあるのは不親切だと思うtig
js
const buffer = //... const embed = new Discord.MessageEmbed() .attachFiles([new Discord.MessageAttachment(buffer, "thumbnail.jpg")]) .setThumbnail("attachment://thumbnail.jpg");

ここではサムネイルを例としているが Image や Auther、Footerなどでも使用できる
ちなみに、内部では普通の添付ファイルと同じように扱われているので 埋め込み 内で添付したファイルを使用しない場合通常の添付ファイルと同様に扱われる。

関連