Hi,
You probably know the default way of sending a message to discord if not look here. Now I’ve been working on some stuff that handles Discord Embeds (that I will talk about later) (and here are their limits). And because I want you all to learn something I will explain it in here.
For this tutorial, we’re going to make a basic function that lets us send embed’s easier for that were going to make a function. As given in the basic tutorial on how to send Discord Messages were going to edit a few things about that. Let us start with the PerformHttpRequest
PerformHttpRequest('DISCORD_URL', function(err, text, headers) end, 'POST', json.encode({username = name, content = message}), { ['Content-Type'] = 'application/json' })
Now to have an embedded message we are going to change content = message to embeds = embed now for this tutorial we’re going to make a basic function first
function sendToDiscord()
PerformHttpRequest('DISCORD_URL', function(err, text, headers) end, 'POST', json.encode({username = name, embeds = embed}), { ['Content-Type'] = 'application/json' })
end
Now this, of course, wouldn’t work because it doesn’t know what name and embed is. We’re going to fix name later, let us make the embed first.
function sendToDiscord()
local embed = {
{
--stuff
}
}
PerformHttpRequest('DISCORD_URL', function(err, text, headers) end, 'POST', json.encode({username = name, embeds = embed}), { ['Content-Type'] = 'application/json' })
end
Now where stuff is located were going to place some information about the message. Like the color on the left side and the title and the text it contains. For Lua it is like any other language but it doesn’t really use fields, i’ven’t tried it though. here is an example. So let us use this example for our own embed
function sendToDiscord()
local embed = {
{
["color"] = color,
["title"] = "**".. name .."**",
["description"] = message,
["footer"] = {
["text"] = footer,
},
}
}
PerformHttpRequest('DISCORD_URL', function(err, text, headers) end, 'POST', json.encode({username = name, embeds = embed}), { ['Content-Type'] = 'application/json' })
end
Now were still going to need some inputs before it could work. as you can see we need: color, name, message, footer. This can be done in any way so let us do that in the () in sendToDiscord() because there we need to put it.
function sendToDiscord(color, name, message, footer)
local embed = {
{
["color"] = color,
["title"] = "**".. name .."**",
["description"] = message,
["footer"] = {
["text"] = footer,
},
}
}
PerformHttpRequest('DISCORD_URL', function(err, text, headers) end, 'POST', json.encode({username = name, embeds = embed}), { ['Content-Type'] = 'application/json' })
end
Before we can put anything in this function we need some understanding in what the it needs.
For color we need a DECIMAL color, like orange = 16753920.
For name we need a STRING like "System"
For message we need a STRING like "The apple doesn't fall far from the tree"
For footer we need a STRING like "Made by Tazio"
As you can see we use name for the title and username you can change that if you like.
and to active, here is an example
sendToDiscord(16753920, "System", "Look an apple", "Made by Tazio")
I hope y’all learned something new and if you see any error please comment, don’t forget to
if it helped you and have a good day. And here is how I use Discord Embeds.
-Tazio