AttachmentBuilder.file constructor

AttachmentBuilder.file(
  1. String path, {
  2. String? description,
  3. String? overrideFilename,
})

Create an attachment from a path

Example :

await interaction.reply(
  content: 'Hello World!',
  attachments: [AttachmentBuilder.file('assets/hello.png', description: 'Idk']
);

You can integrate image in embeds :

await interaction.reply(
  content: 'Hello World!',
  attachments: [AttachmentBuilder.file('assets/hello.png', description: 'Idk'],
  embeds: [EmbedBuilder(title: 'How are you?', thumbnail: Thumbnail(url: 'attachment://hello.png'))]
);

Implementation

factory AttachmentBuilder.file(String path, {String? description, String? overrideFilename}) {
  File file = File(join(Directory.current.path, path));
  return AttachmentBuilder(file.readAsBytesSync(), filename: basename(file.path), description: description);
}