Embeds & Attachments
Embeds
Embeds in lilybird are a 1:1 of the discord docs, to put it simple, they are just plain objects with no abstractions or name changes.
To send an embed you just need to pass it to any method that supports it (liked createMessage
and createInteractionResponse
).
19 collapsed lines
1import {2 InteractionCallbackType,3 InteractionType,4 createClient,5 Intents6} from "lilybird";7
8await createClient({9 token: process.env.TOKEN,10 intents: [Intents.GUILDS],11 // We pass the setup function we created above12 setup,13 listeners: {14 interactionCreate: async (client, payload) => {15 // We only want to handle guild interactions16 if (!("guild_id" in payload)) return;17 // We only want to handle application commands18 if (payload.type !== InteractionType.APPLICATION_COMMAND) return;19
20 await client.rest.createInteractionResponse(interaction.id, interaction.token, {21 type: InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE,22 data: {23 embeds: [24 {25 title: "Hello, Embed!",26 description: "This is an embedded message."27 }28 ]29 }30 });3 collapsed lines
31 }32 }33});
Attachments
Attachments in lilybird work a bit differently from what you might be used to.
Methods that accept attachments will have an extra field usually called files
where you pass an array with the files you want to make attachments, the client will auto generate the attachments
field for you.
19 collapsed lines
1import {2 InteractionCallbackType,3 InteractionType,4 createClient,5 Intents6} from "lilybird";7
8await createClient({9 token: process.env.TOKEN,10 intents: [Intents.GUILDS],11 // We pass the setup function we created above12 setup,13 listeners: {14 interactionCreate: async (client, payload) => {15 // We only want to handle guild interactions16 if (!("guild_id" in payload)) return;17 // We only want to handle application commands18 if (payload.type !== InteractionType.APPLICATION_COMMAND) return;19
20 await client.rest.createInteractionResponse(interaction.id, interaction.token, {21 type: InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE,22 data: {23 content: "This message has an attachment!"24 }25 }, [{ file: Bun.file("path/to/your/file.png"), name: "yourfilename.png" }]);3 collapsed lines
26 }27 }28});
Attachments in Embeds
To have your attachment inside an embed for example as an image, all you need to do is pass the url of your attachment to it
19 collapsed lines
1import {2 InteractionCallbackType,3 InteractionType,4 createClient,5 Intents6} from "lilybird";7
8await createClient({9 token: process.env.TOKEN,10 intents: [Intents.GUILDS],11 // We pass the setup function we created above12 setup,13 listeners: {14 interactionCreate: async (client, payload) => {15 // We only want to handle guild interactions16 if (!("guild_id" in payload)) return;17 // We only want to handle application commands18 if (payload.type !== InteractionType.APPLICATION_COMMAND) return;19
20 await client.rest.createInteractionResponse(interaction.id, interaction.token, {21 type: InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE,22 data: {23 embeds: [24 {25 title: "Hello, Embed!",26 description: "This is an embedded message with an image.",27 image: { url: "attachment://yourfilename.png" }28 }29 ]30 }31 }, [{ file: Bun.file("path/to/your/file.png"), name: "yourfilename.png" }]);2 collapsed lines
32 }33 }34});