How to use Cloudflare Workers for sending Discord Messages
Welcome! In this tutorial, I will guide you on how to use Cloudflare for sending messages to discord.
Requirements
- A Cloudflare account
- Roblox Module
- Code located on GitHub
Tutorial
Part 1: Cloudflare Setup
Start by heading to Cloudflare and creating a new Worker, name it whatever you want and save the Worker URL, as this will be the endpoint in which you will use to send messages to discord.
Navigate in the Tutorial Repo and copy the text inside the cloudflare.js
file. This file will contain everything that you will need for the Backend part.
Change the AUTH_TOKEN
to whatever you want. Just make sure it is secure and DO NOT share it with anyone.
Optional: You can modify the rateLimit
to whatever suits you. By default, it is 2 messages per second per Webhook.
That’s it! Deploy your worker and you are ready to send messages to Discord!
Part 2: Roblox Setup
Grab the model from here and place it into ServerScriptService
.
Open up the Example Script
. There, you can customize the appearance of your Discord Message to send. Thanks to the new BitHook Module, it makes sending embeds really simple! The example script is as follows:
local BitHook = require(game.ServerScriptService.BitHook)
local embed = {
title = "Embed Title",
description = "This is a detailed description of the embed.",
url = "https://example.com",
color = 16711680,
author = {
name = "81Frames",
url = "https://example.com/author",
},
fields = {
{
name = "Field 1",
value = "This is the value for field 1.",
inline = true
},
{
name = "Field 2",
value = "This is the value for field 2.",
inline = true
}
},
footer = {
text = "Footer text goes here",
},
timestamp = "2025-01-01T00:00:00Z"
}
local cloudflareWorkerUrl = "YOUR_CLOUDFLARE_WORKER"
local discordWebhookUrl = "YOUR_WEBHOOK_URL"
local authToken = "YOUR_API_TOKEN"
local response = BitHook.SendMessage(cloudflareWorkerUrl, discordWebhookUrl, authToken, embed)
if response then
print("Response:", response)
else
print("Failed to send message.")
end
Just to test that it is working, edit the script’s CloudflareWorkerURL
, AUTH_TOKEN
, and your WebhookURL
to whatever yours are. Run the script in studio and insure that HTTPService is enabled. You should see a new message in your Discord channel and it should look something like this:
If this example works! You are now welcome to edit the script to do what you want it to do! The Embed Message supports everything including passing images.
That concludes the tutorial, and thanks for reading.
Extra Service:
If you don’t want to self host this tutorial for whatever reason, you can try the public version of this Project! Just insert the BitHook Module from the Roblox Store and edit theAUTH_TOKEN
to81frames
and theWORKER_URL
tohttps://bithook.email-277.workers.dev/
For more information, check out the latest update post.