Discord Embed Tutorial (OUTDATED)

Hello, Developers!

So since I was bored, I hoped on the Developer Forum today and I wanted to teach beginning programmers something new about discord embeds, so why not do a tutorial?

Step 1: Define your variables.
Since we will be using HTTP Service for our discord embeds, let’s define HTTP Service by typing in the following code.

local HttpService = Game:GetService ("HttpSerivce")

Now that we have our HTTP Service variable defined, let’s define our webhook. We would do that like this:

local webhook = "put webhook here" --Put your discord webhook here.

We need to also define our json data.

local jsonData = HttpService:JSONEncode(data)

Note this goes at the end of your code.

Step 2: A basic message.
In this step, we see how a basic message is put together on discord. If you just want a basic message the code would look something like this:

local data = {
["content"] = "" --Put whatever content you would like to have here.
}

Note the code above is not yet a discord embed but rather just a message. If you put something random into that, it would post it like a normal message is sent on discord.

Step 3: Embeds
In this step, we learn how to make an embed. Adding onto the basic message step that we did just a little bit ago, we now will make it more advanced.

local data = {
["content"] = "",
["embeds"] = {{
["title"] = "put whatever here", -- The title will be bolded by default when posted on discord.
}
           }
}

We can add some color by putting in a color field just after the embeds.

["color"] = 0001, -- This color is black.

If you would like to add fields to your embed, it would look something like this:

["fields"] = {
						{
							["name"] = value,
							["value"] = value
						}
}

If you would like to have a variable In those values, you will need to define those at the top of your code.

Finally, we need to put this final touch at the end of our code:

HttpService:PostAsync(webhook, jsonData)

This just posts the embed for us onto discord.

The Final Code should look like this:

local HttpService = game:GetService ("HttpService")
local webhook = "" -- Put webhook here

local data = {
	["content"] = "", -- Whatever content you would like to put here, this could be a discord mention.
	["embeds"] = {{
		["title"] = "", --Put your title here
		["color"] = 0001, -- This color is black.
		["fields"] = {
			{
				["name"] = "", -- This is  the title of your field.
				["value"] = "" -- This is the value of your field.
			}

		}}
	}
	}

	local jsonData = HttpService:JSONEncode(data)
	HttpService:PostAsync(webhook, jsonData)

In short, discord embeds can be used for a lot of things including logs from your game, etc. Just note that the limit for HTTP Requests on Roblox is 500 requests every minute, so you need to make sure that your embeds are not using all those requests.

It is also strongly advised not to use embeds for chat logs because those take up a lot of requests.

I hope you enjoyed this tutorial, please shoot me a message or leave a comment If you have any questions for me!

15 Likes

Very unique tutorial! Nice as well, I could definitely use this.

2 Likes

If anyone is looking for full documentation on embeds, it can be found here.

That is just for the service, Discord has an even lower limit, of 30 per minute per channel. I would include this.

4 Likes

What is the color format? i tried hex but its not right.

You should not be using discord for logs of any kind. One of the only use-cases you could use Discord for is application centers and in-game suggestions/feedback or moderation reports.

Do not use it for logging, using Discord for logging may result in your Discord server being deleted. It is not designed for logging and you should use other services that are designed for logging data such as Sentry or Google Sheets

Please avoid using Discord for these types of things

1 Like