Skip to content

Message Attachments

Attachments are a way to upload files to the Discord CDN, discord luau supports sending these attachments through the AttachmentBuilder object.

  1. 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
    ...
    end
    end)
    DiscordClient.eventManager.onReady:connect(function()
    print(`πŸŽ‰πŸŽ‰ {DiscordClient.discordUser.username} is online! πŸŽ‰πŸŽ‰`)
    end)
    DiscordClient:connectAsync()
  2. 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!")
  3. 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))
end
end)
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;