Roblox Discord Message Embed Class

Roblox Message Embed

I’ve wanted a simple way to quickly send message embeds to discord. Having discord integration in your game can help in all sorts of ways. As someone who has worked with discord.js frequently, I wanted a similar functionality that discord.js message embeds provide.

Example

This example assumes that the class is a child of the script. Also, I know there is a webhook included within this, it has already been deleted in discord.

local MessageEmbed = require(script.MessageEmbed)

local fieldsToAdd = {
	{"testing", "other testing"},
	{"more testing", "even more testing"}
}

local embed = MessageEmbed.new("https://discordapp.com/api/webhooks/556545042198560798/Kjk3NvUGZgyWvq4vNoKg5xKgKp1K2YiQEV4uj8fvScbZVkxzO8VnpyYYiqFNU_Feqy3a")
embed:SetTitle("Test")
embed:SetDescription("more test")
embed:AddField("testing", "other testing")
embed:AddFields(fieldsToAdd)
embed:SetColor(16770680)
embed:SetFooter("created by tomspell", "https://tr.rbxcdn.com/6a63f2b5da298c220feef4294755709c/150/150/AvatarHeadshot/Png")
embed:SetImage("https://tr.rbxcdn.com/6a63f2b5da298c220feef4294755709c/150/150/AvatarHeadshot/Png")
embed:SetThumbnail("https://tr.rbxcdn.com/6a63f2b5da298c220feef4294755709c/150/150/AvatarHeadshot/Png")
embed:SetUrl("https://www.roblox.com/users/9345226/profile")

embed:PostAsync()

As you can see, this class uses the exact same methods as discord.js message embeds, and take in the exact same parameters. The only difference is when you create the message embed, you pass the webhook parameter into the function, which allows you to post the embed.

Links

Feel free to grab the class here:

Roblox Model: MessageEmbed - Roblox
Github: GitHub - Zenthial/Roblox-Message-Embed: A simple class that allows roblox developers to easily send messages to discord

Disclaimer

This is not meant to be used as a logging service for your game, as discord’s ToS does not allow for discord to be used as a logging service. I’d recommend using trello or even slack instead.

25 Likes

Wow! This seems really useful and will definitely save me a lot of time integrating my game with discord. Will check this out for sure!

1 Like

Is there a way to prevent players from saying “@here” or @everyone" in-game and having it ping people in servers.

Has that actually ever happened before when using one of these in-game? Yes, there’s ways to prevent it if it actually has happened at one point. You could just turn off those permissions for people in your discord server with specific roles and if they do it in-game it won’t ping everyone or the channel.

If you were to use this to log everyone’s messages in-game, which I wouldn’t recommend due to discord rate limits, you could simply do this on your chatted function

game.Players.PlayerAdded:Connect(function(player)
   player.Chatted:Connect(function(text)
      if string.match(text, "@here") or string.match(text, "@everyone") or string.match(text, "<@") then return end
    -- Handle the rest of what you want to do with the player's message
   end
end
1 Like

Thank you! I really needed this. :+1:

2 Likes

Don’t use Discord as a logging service. They will suspend your API access if they catch you.

ESPECIALLY do not use it to log player chat. Someone could say something NSFW in chat, which would be automatically flagged by Discord, and… get your account terminated.

I’ll reiterate, Do not use discord as a logging service

4 Likes

Are you sure they do that? Have you had that or know someone whos had that happen to them?

1 Like

Yes.

Yes.


It’s also just common sense that you don’t use an instant messenger for logging. Trello is, frankly, a better logging solution than Discord. (Doesn’t mean you should use ith though!!)

1 Like

You can prevent this spam with RequestAsync. Why hasn’t anyone mentioned this useful function for rate limiting except this public Discord webhook module thread?

1 Like

The intended function of the class doesn’t concern itself with rate limits. The entire goal of this project was to make a embed class similar to discord.js. If developers wish to use lots and lots of embeds very quickly, it falls upon them to add rate limits.

However, as it stands, most developers are not sending lots and lots of embeds at a very rapid pace, which reduces the need for any rate limiting on the classes’ end.

1 Like

I understand that but if rate limiting becomes a problem, wouldn’t you suggest this solution?

Also, I’m directly talking about people who want to send messages in any case rather than the embed module itself.

1 Like

Yeah of course you could, and I’ve done that for a while now. I just made this for people who don’t want to do that, or are used to the discord.js message embed. I plan on adding most of the settings directly to the constructor in the next version I commit to github as well.

2 Likes

Wow! Thank you so much Tomspell! I will for sure be using this at my game! Epic!

1 Like

Something that got added in discord.js v12 (I think) was the ability to add multiple fields without constantly having to do :AddField(). That method is called :AddFields(). I recommend adding that to your module and passing in a table of fields as a parameter.

3 Likes

Added that :slight_smile:

 local fieldsToAdd = {
	{"testing", "other testing"},
	{"more testing", "even more testing"}
}
embed:AddFields(fieldsToAdd)

Takes in a table of fields, with each individual field also being a table. Live on both the roblox model and the github.

2 Likes

Discord like any other company has rate limits, you should check their Legal information and Rate-limit information as it will guide you through the information you should acknowledge before logging all actions for your Discord server. Quite frankly, yes, the embedded messages, cool system and chatting is extraordinarily great to control but to protect your account, server and members you should go with something more basic like ElliottLMz stated but go with something that can handle every-second request and chatting issues and is not logged to the company or flagged.

2 Likes

Is there a way to make the field’s have a link so that when you click it, it actually takes you to a URL?

1 Like

Sorry for the late response. Just like normal embeds, you can just drop links normally, or if you want to hyperlink text, you can use the (text)[link] format.

1 Like