Skip to content

Commit

Permalink
Add docs about embeds and attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
Didas-git committed Jul 14, 2024
1 parent 4f122d2 commit 724a0cc
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 9 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"UPSELL"
],
"typescript.tsdk": "node_modules/typescript/lib",
"eslint.experimental.useFlatConfig": true,
"eslint.format.enable": true,
"eslint.enable": true,
"[typescript]": {
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions packages/docs/astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export default defineConfig({
},
{
label: "Modules",
collapsed: true,
items: [
{
label: "JSX Components",
Expand Down
12 changes: 6 additions & 6 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"devDependencies": {
"@expressive-code/plugin-line-numbers": "^0.35.3",
"@expressive-code/plugin-collapsible-sections": "^0.35.3",
"@astrojs/check": "^0.7.0",
"@astrojs/starlight": "^0.24.3",
"starlight-typedoc": "^0.12.2",
"typedoc": "^0.25.13",
"typedoc-plugin-markdown": "^4.0.3",
"astro": "^4.10.3",
"@astrojs/check": "^0.8.1",
"@astrojs/starlight": "^0.25.1",
"starlight-typedoc": "^0.13.0",
"typedoc": "^0.26.4",
"typedoc-plugin-markdown": "^4.2.1",
"astro": "^4.11.5",
"sharp": "^0.33.4"
}
}
2 changes: 0 additions & 2 deletions packages/docs/src/content/docs/guides/coloring.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
title: Coloring
description: Learn the ways you can color embeds and text in discord using lilybird.
sidebar:
order: 4
---

In discord, customization of colors and specific accents is allowed in a limited set of places: Embed accents and ANSI Blocks.
Expand Down
126 changes: 126 additions & 0 deletions packages/docs/src/content/docs/guides/embeds-attachments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
title: Embeds & Attachments
description: Learn how to use embeds and send attachments with lilybird.
sidebar:
order: 4
---

## Embeds

Embeds in lilybird are a 1:1 of the [discord docs](https://discord.com/developers/docs/resources/channel#embed-object-embed-structure), 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`).

```ts showLineNumbers collapse={1-19, 31-33}
import {
InteractionCallbackType,
InteractionType,
createClient,
Intents
} from "lilybird";

await createClient({
token: process.env.TOKEN,
intents: [Intents.GUILDS],
// We pass the setup function we created above
setup,
listeners: {
interactionCreate: async (client, payload) => {
// We only want to handle guild interactions
if (!("guild_id" in payload)) return;
// We only want to handle application commands
if (payload.type !== InteractionType.APPLICATION_COMMAND) return;

await client.rest.createInteractionResponse(interaction.id, interaction.token, {
type: InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
embeds: [
{
title: "Hello, Embed!",
description: "This is an embedded message."
}
]
}
});
}
}
});
```

## 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.

```ts showLineNumbers collapse={1-19, 26-28}
import {
InteractionCallbackType,
InteractionType,
createClient,
Intents
} from "lilybird";

await createClient({
token: process.env.TOKEN,
intents: [Intents.GUILDS],
// We pass the setup function we created above
setup,
listeners: {
interactionCreate: async (client, payload) => {
// We only want to handle guild interactions
if (!("guild_id" in payload)) return;
// We only want to handle application commands
if (payload.type !== InteractionType.APPLICATION_COMMAND) return;

await client.rest.createInteractionResponse(interaction.id, interaction.token, {
type: InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
content: "This message has an attachment!"
}
}, [{ file: Bun.file("path/to/your/file.png"), name: "yourfilename.png" }]);
}
}
});
```

### 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

```ts showLineNumbers collapse={1-19, 32-33}
import {
InteractionCallbackType,
InteractionType,
createClient,
Intents
} from "lilybird";

await createClient({
token: process.env.TOKEN,
intents: [Intents.GUILDS],
// We pass the setup function we created above
setup,
listeners: {
interactionCreate: async (client, payload) => {
// We only want to handle guild interactions
if (!("guild_id" in payload)) return;
// We only want to handle application commands
if (payload.type !== InteractionType.APPLICATION_COMMAND) return;

await client.rest.createInteractionResponse(interaction.id, interaction.token, {
type: InteractionCallbackType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
embeds: [
{
title: "Hello, Embed!",
description: "This is an embedded message with an image.",
image: { url: "attachment://yourfilename.png" }
}
]
}
}, [{ file: Bun.file("path/to/your/file.png"), name: "yourfilename.png" }]);
}
}
});
```

0 comments on commit 724a0cc

Please sign in to comment.