EmbedBuilderを使って埋め込みを送信するサンプル
jsconst { Client, EmbedBuilder, GatewayIntentBits } = require('discord.js');
const options = {
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
};
const client = new Client(options);
client.on('messageCreate', message => {
if (message.content === '!embed') {
const embed = new EmbedBuilder()
.setTitle('埋め込みのタイトル')
.setURL('https://google.com')
.setFields({ name: 'name', value: 'value'})
.setColor('Random')
.setTimestamp()//引数にはDateオブジェクトを入れることができる。何も入れないと今の時間になる
message.channel.send({ embeds: [embed] })
}
})
client.login('token')
実行結果:
embed.jsconst embed = new EmbedBuilder()
.setTitle('埋め込みのタイトル 256字まで')
.setDescription('埋め込みの説明 4096字まで')
.setAuthor({
name: '著者名 256字',
iconURL: 'https://gyazo.com/520c092f191cf3c7dcd75a559b7dd536/max_size/1000'
})
.setURL('https://google.com')
.setThumbnail('https://gyazo.com/520c092f191cf3c7dcd75a559b7dd536/max_size/1000')
.setImage('https://p.kindpng.com/picc/s/108-1084174_discord-js-discord-js-logo-png-transparent-png.png')
.setFields(
{
name: 'json形式で書けるフィールド、こっちは名前で最大256字',
value:'フィールドの値 ※1024字まで'
},
{
name: '`{name:"name",value:"value"}`で1セット',
value:'足りないとエラーが出る'
}
)
.addFields({name: 'inline: trueを加えることで', value: 'インラインにできる', inline: true})
.setColor('#00ff00')
.setFooter({
text: '埋め込みのフッター 2048字まで\n埋め込み全体の文字数は6000字まで\n一つのメッセージで送れる埋め込みは10個'
})
.setTimestamp()
message.channel.send({ embeds: [embed] });