Message Attachments
Attachments are a way to upload files to the Discord CDN, discord
luau supports sending these attachments through the AttachmentBuilder
object.
-
Create a discord-luau bot implementation:
local DiscordLuau = require("DiscordLuau")local DiscordSettings = DiscordLuau.SettingsBuilder.new("<DISCORD_TOKEN>")local DiscordClient = DiscordLuau.DiscordClient.new(DiscordSettings)DiscordClient.eventManager.onMessage:connect(function(message)if message.content == "!embed" then...endend)DiscordClient.eventManager.onReady:connect(function()print(`ππ {DiscordClient.discordUser.username} is online! ππ`)end)DiscordClient:connectAsync() -
Create a Discord attachment that we can respond with:
local responseAttachment = DiscordLuau.AttachmentBuilder.new():setName("example.txt"):setDescription("Example Text Document"):setData("Hello, World - 'Tis be the data of this example document!") -
Reply to the message with the newly created embed:
local responseMessage = DiscordLuau.MessageBuilder.new()local responseAttachment = DiscordLuau.AttachmentBuilder.new():setName("example.txt"):setDescription("Example Text Document"):setData("Hello, World - 'Tis be the data of this example document!")message:replyAsync(responseMessage:addFile(responseAttachment))
See The Entire Code
local DiscordLuau = require("DiscordLuau")
local DiscordSettings = DiscordLuau.SettingsBuilder.new("<DISCORD_TOKEN>")local DiscordClient = DiscordLuau.DiscordClient.new(DiscordSettings)
DiscordClient.eventManager.onMessage:connect(function(message) if message.Content == "!embed" then local responseMessage = DiscordLuau.MessageBuilder.new() local responseAttachment = DiscordLuau.AttachmentBuilder.new() :setName("example.txt") :setDescription("Example Text Document") :setData("Hello, World - 'Tis be the data of this example document!")
message:replyAsync(responseMessage:addFile(responseAttachment)) endend)
DiscordClient.eventManager.onReady:connect(function() print(`ππ {DiscordClient.discordUser.username} is online! ππ`)end)
DiscordClient:connectAsync()
Thatβs all! For more details, refer to the relevant docs;