Responding with Embeds
Embeds are a way to display rich content in Discord messages. They allow you to include images, formatted text, fields, and other interactive elements within a message.
-
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() -
Allow the bot to check messages:
- Go to the Discord Developer Portal
- Choose your bot application in the
Applications
tab - Go to the
Bot
tab and enableMESSAGE CONTENT INTENT
-
Create a Discord embed that we can respond with:
local responseEmbed = DiscordLuau.EmbedBuilder.new():setTitle("Example Embed"):setDescription("This is an example of an embed created using DiscordLuau!"):setColor(0xFF0000):addField("Field 1", "Value 1", true):addField("Field 2", "Value 2", true):setFooter("This is a footer") -
Reply to the message with the newly created embed:
local responseMessage = DiscordLuau.MessageBuilder.new()local responseEmbed = DiscordLuau.EmbedBuilder.new():setTitle("Example Embed"):setDescription("This is an example of an embed created using DiscordLuau!"):setColor(0xFF0000):addField("Field 1", "Value 1", true):addField("Field 2", "Value 2", true):setFooter("This is a footer")message:replyAsync(responseMessage:addEmbed(responseEmbed))
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 responseEmbed = DiscordLuau.EmbedBuilder.new() :setTitle("Example Embed") :setDescription("This is an example of an embed created using DiscordLuau!") :setColor(0xFF0000) :addField("Field 1", "Value 1", true) :addField("Field 2", "Value 2", true) :setFooter("This is a footer")
message:replyAsync(responseMessage:addEmbed(responseEmbed)) 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;