Discord Integration: A guide on using Discord through Roblox [UPDATED]

Introduction

I’ve been scripting for a long time, and as a result, I’ve come up with various different ways to do things as opposed to more traditional methods. One of these methods I’ve come up with is using Discord Webhooks to track and/or notify me of whats happening in my game. Without further ado, here’s the tutorial.


What is a Discord Webhook?

a Discord Webhook is a handy little feature built into Discord that allows developers to send messages without the use of a bot(and in-turn a web server). These Webhooks are usable through POST requests, and can only be used to send messages. By using these hooks, developers can do anything from error monitoring to even logging when players join and leave their game.


Setting up a Webhook on your Discord Server

Adding a Webhook to your server is incredibly easy.

Step 1. Open the Discord Server on which you want to put the Webhook.

(No screenshot :frowning: )

Step 2. Click the dropdown arrow and open Server Settings.

Step 3. Open the Webhooks tab and click Create Webhook.

Step 4. Configure the Webhook to your liking and then save the link(We’ll need this later).


Interacting with the Webhook

Now that the webhook is set up, we can move on to using it in Roblox. Before we get into the code, make sure that HTTPService is enabled. If you don’t know how, type this in your command bar:

game:GetService("HttpService").HttpEnabled = true

Now that HTTPService is enabled, we can get into the actual code of this tutorial. To use the webhook, we will have to use the PostAsync function of HTTPService. Here’s a basic example:

local http = game:GetService("HttpService")
local Data = {
	["content"] = "Hey! This is a message sent from roblox!"
}

Data = http:JSONEncode(Data)

http:PostAsync("", Data) --Put the link you saved between the two quotes.

When we run this code, it’ll send a message looking something like this:


What else can we do with this?

Just about anything! Discord will automatically detect and implement any markdown you have in your code, so the possibilities are endless! Here’s a couple of examples of what I like do with these:

Error Monitoring

local HTTPService = game:GetService("HttpService")
local url = "[Discord url here]"

game:GetService("ScriptContext").Error:Connect(function(msg, stacktrace, scriptt)
	local Data = {
		["username"] = "Error Monitor";
		["content"] = "```lua\n"..msg.."\n "..stacktrace.."```";
	}
	Data = HTTPService:JSONEncode(Data)
	HTTPService:PostAsync(url, Data)
end)

WARNING: Do NOT use this if your game has high traffic. It could potentially lead to your Discord account being terminated.

Player Join Tracker

local http = game:GetService("HttpService")

game:GetService("Players").PlayerAdded:Connect(function(player)
	if not game:GetService("RunService"):IsStudio() then
		local date = os.date("!*t")
		local Data = {
			["content"] = player.Name.." joined your game on "..date.month.."/"..date.day.."/"..date.year
		}
		Data = http:JSONEncode(Data)
		http:PostAsync("[Discord hook here]", Data)
	end
end)

Final Notes

If you have any feedback on this tutorial, feel free to contact me either through the DevForums, or by PMing me directly on the roblox website. If you’d like to know more about what webhooks can do, check out this link: Discord Developer Portal.

UPDATE

Luckily @FoxbyDev was already working on an API, and has finished it! Here’s a link to his:

394 Likes
Webhooks + In game Admin
Discord Webhooks to Roblox
Recording Time Spent in Game
Game Design Theory: Planning a Game and Implementing Features
Roblox to Discord Bot
How can I make a Button, If you bought a Gamepass and clicked it a webhook will send message to discord?
Advanced Webhooks
Send message to discord server from game?
Support system game
Game Statistics
Discord bot help
Interact With A Discord Bot
Commander | Open Sourced Admin Panel
Idea for a notification system, suggestions and feedback
Is there any way to connect some discord server information and connect it into my roblox game?
Discord BOT online/offline
Purchase bot for discord help
Discord Integration
How to make a report player button
How can I make a Button, If you bought a Gamepass and clicked it a webhook will send message to discord?
Member Count bot!
How to make joinlogs w/ a discord webhook?
How to use Roblox's HTTP Service to communicate with discord js
Ingame developer contact/feedback section
Help creating a discord webhook
Discord bot help
Report in custom chat?
Trying to save if a player was lucky
Why am I getting a bad HTTP 400 Request Error?
How do you create embedded messages?
Textbox webhook logger?
How do you set up a HTTP service to print things from roblox?
HttpService Bad Request
The best way to secure scripts for products
How can I get notified If you bought a Devproduct a webhook will send message to discord
How do I make roblox send data in httpsservice?
How can i send value from roblox to discord bot
How do I receive an email or some type of notification when someone joins my game?
How would I make a discord bot that logs my Completed Trades?
How can I fix the Http 400 bad request error Discord Webhook
Hyper Realistic SCP Foundation?
Issues discord send message
How do I format like this on webhook?
Integrations from Roblox to Discord
Integrations from Roblox to Discord

There is a discord webhook API in the models made by Tigerism that works really well. I don’t think it supports embeds or anything of sort, just messages. Good tutorial though, good luck expanding it.

EDIT: Direct requests to Discord from Roblox no longer work, so I am going to assume that this API isn’t functional.

35 Likes

Also good to mention that you should wrap the PostAsync in a pcall function because it will fail from time to time.

13 Likes

This is actually against Discord’s TOS. I’d definitely advise against it.

57 Likes

That’s strange. Why would they block an error monitor?

9 Likes

Maybe it’s too resource intensive depending on the amount of errors

16 Likes

I actually replied & asked if it was b/c of resources, but he just responded with this:

My best guess would be that they allow webhooks for stuff meant for Discord (like bots), and not people using it to send stuff.

23 Likes

That makes sense I guess. I’ll remove the error monitoring part.

7 Likes

You can leave it up there since it’d still help people out, but I had one logging errors for Survivor (which got 29k players at once), so I’m assuming the high amount of http requests made them look into what it was for. As long as your game doesn’t have a lot of players at once, they probably won’t ever check it.

7 Likes

Can definitely agree with @repotted that lower traffic is probably fine. My game had 3k players on at once sending reports without any problems.

7 Likes

Yeah, that’s probably why :grimacing:. I’ll put it back up there with a warning so people don’t get their discords terminated.

11 Likes

I talked to a few of the Discord developers about this and it would seem that the main issue was certain developers not being meticulous about how many requests they were sending. For example, if you have an error that triggers multiple times per second because of some unchecked bug, you would basically be DDoSing Discord with POST requests. I’d say they likely mitigate this by checking certain headers that were present in the request that would reveal it was sent from a ROBLOX server.

There are several very high-profile servers that actively use Discord to log important errors, so I’m going to guess they aren’t completely opposed to error logging on the platform but ban it in the case of ROBLOX due to the very high potential of API abuse.

Then again, some people are still sending webhook messages through ROBLOX; perhaps this is because they’re only going after people causing trouble or they have a certain check setup like “if sent from ROBLOX and channel name includes ‘error’…”

TLDR: Use Sentry, it’s awesome and actually made for error logging.

19 Likes

Please do not spam discord. If too many people do this they may just blacklist roblox server IPs in general and that would ruin it for everyone who doesn’t abuse it.

25 Likes

Would it be better to just remove the monitor in general? Some people with malicious intent might be viewing this.

4 Likes

It’s kind of unavoidable. Worst case scenario those who use it responsibly can set up a proxy for very cheap (cheap because they aren’t overloading it!!)

4 Likes

Alright. Thanks for the feedback all of you by the way.

5 Likes

I haven’t used webhooks in a while, but I think you can send multiple embeds in one HTTP request. You could group several messages (each as a separate embed) into one request.

Actually lemme test:

{
  const url = 'https://canary.discordapp.com/api/webhooks/343362987622662144/z6r8217KiNVhWxf3SbnOaX8fQ4__TptWNvApVM3VqgybOXdQOE5-sgy00D4nMio7g89-';

  function embed(title, desc, color, author) {
    return {
      timestamp: "2017-07-11T17:27:07.299000+00:00",
      title,
      desc,
      color,
      author: {
        name: author,
        icon_url: 'https://cdn.discordapp.com/emojis/339896242211389450.png'
      },
      fields: [
        {
          name: 'A',
          value: 'B',
          inline: true
      },
        {
          name: 'A',
          value: 'B',
          inline: true
      },
        {
          name: 'A',
          value: 'B',
          inline: true
      },
        {
          name: 'A',
          value: 'B',
          inline: true
      },
    ]
    }
  }

  console.log(embed('a', 'b', 0xFFFFFF, 'einsteinK'));

  $.post(url, JSON.stringify({
    embeds: [
    embed('Title1', 'Description1', 0xFF0000, 'einsteinK'),
    embed('Title2', 'Description2', 0x00FF00, 'einsteinK'),
    embed('Title3', 'Description3', 0x0000FF, 'einsteinK'),
  ]
  }), console.log);
}

I already deleted the webhook to prevent spam. thanks to antonio6643#8700 for pointing that out

16 Likes

We actually attempted to do that with the egg hunt this year and did not get such a message. We hit like all rate limits though so we had to remove it after a few hours.

4 Likes

Honestly depends on what you’re using it for, and if your game is constantly printing things in the console.

2 Likes

:pray: A user some months back linked me to Tigerism’s stuff, tons of coolness. This tutorial will hopefully spread the neat usage of Discord integration in ROBLOX.

3 Likes