ローカルの画像を埋め込みで使用するサンプル
AttachmentBuilder
を使用する。
.setName(name)
と .setThumbnail(attachment://name)
の name
は同じにしておく。(これは識別用?)
.setFile(attachment)
の attachment
内はファイルパス、Buffer、FileStreamなどが使用可能。
jsconst { 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]
})
attachment://<ファイル名>.<拡張子>
の形式で添付したファイルにアクセスできる。
jsconst buffer = //...
const embed = new Discord.MessageEmbed().setThumbnail("attachment://thumbnail.jpg");
const attachment = new Discord.MessageAttachment(buffer, "thumbnail.jpg");
channel.send({ files: [attachment], embeds: [embed] });
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.
正直ここに書いてあるのは不親切だと思う

jsconst buffer = //...
const embed = new Discord.MessageEmbed()
.attachFiles([new Discord.MessageAttachment(buffer, "thumbnail.jpg")])
.setThumbnail("attachment://thumbnail.jpg");
ここではサムネイルを例としているが Image や Auther、Footerなどでも使用できる
ちなみに、内部では普通の添付ファイルと同じように扱われているので
埋め込み 内で添付したファイルを使用しない場合通常の添付ファイルと同様に扱われる。
関連