Discord webhook won't send messages due to a "bad request"

I am trying to make a Gui in my game were you put a message in a TextBox, press a button, and then sends that message to a discord server.

The problem is that every time I put a message and click the send button, it makes an error that says “HTTP 400: Bad Request” on line 10 (the script is at the bottom).

By the way I have checked the DevForum and the roblox developer wiki (whatever it’s called), and I haven’t found a solution that has worked in either of those places.

local HS = game:GetService("HttpService")
local WebHook = --My discord webhook that I'm not making public
local textttttt = game.Workspace.message.Value
	
script.Parent.MouseButton1Click:Connect(function()
	local MessageData = {
		["content"] = textttttt
	}
	local DiscordMessageData = HS:JSONEncode(MessageData)
	HS:PostAsync(WebHook, DiscordMessageData) --This is line 10
end)

Did I remember or did I stutter
But I think Discord Webhooks are banned I guess

First thing to ask, I believe that is a localscript? I don’t think HttpService’s PostAsync method is available to be used in client side.

What I would do is pass that data to a remote event, and use the PostAsync method in the function connected to the remote event.

Yeah they were banned from Discord as far as I know. Nothing on Roblox’s side. I think there are some services that let you forward webhooks.

Discord no longer prohibits requests from the Roblox servers; it has been over a year since they removed the block.

Ah. It’s been a while since I’ve done webhook stuff.

1 Like

Have you tried just sending a string, like "Hello!"?
The bad request means that you are sending something that is invalid, such as a boolean where a string should be, an array, a function, or an undefined JSON value.
Try printing typeof(textttttt).
Make sure your link is correct, and in the correct format.
Double, and triple check everything is correct.
I did your code in a server script and it sent a message well.

local Text = "hello!"
local Link = "https://discordapp.com/api/webhooks/"
local HttpService = game:GetService("HttpService")

HttpService:PostAsync(Link, HttpService:JSONEncode({
	content = Text
}))

Result was Hello! in my channel.

Howdy there!
As a personal preference, I often enjoy using embeds instead of plain discord messages. The reason for this is that users can simply type in “@everyone” and it will ping everyone.

    local url = "WEBHOOK-URL"
	local http = game:GetService("HttpService")
	
	local data = {
            embeds = {
			{
					color = "COLOR",	
                    author = {name = "AUTHORTEXT"},
                    title = "TITLE-TEXT",
                    type = "rich",
					description = "DESCRIPTION-TEXT",
	
                }
            }
        }
					
	local newdata = http:JSONEncode(data)
	http:PostAsync(url,newdata)

Every field above is optional, if you want the field empty, you can simply remove the text from it.

Hope this helped!

I made this and it seems to work. Feel free to download it and implement it into your own thing.
Test.rbxl (29.6 KB)

Hey there,
Alongside what others have suggested, have you checked your Game Settings? This issue may be due to you not enabling them.

1 Like

Yes, I have enabled studio access to API services and HTTP requests.

Yes, I have tried sending just a string and it works.

The problem with my script was the “textttttt” variable. Turns out if you do .Value in the variable (btw “message” is a StringValue, which is why I put the .Value after it), it will not work. But if I remove the .Value in the variable and then put the .Value part in the function it works. Example is below.

local HS = game:GetService("HttpService")
local WebHook = --My discord webhook that I'm not making public
local textttttt = game.Workspace.message.Value

script.Parent.MouseButton1Click:Connect(function()
	local MessageData = {
		["content"] = textttttt --This won't work since the .Value part is in the variable
	}
 	local DiscordMessageData = HS:JSONEncode(MessageData)
	HS:PostAsync(WebHook, DiscordMessageData)
end)
local HS = game:GetService("HttpService")
local WebHook = --My discord webhook that I'm not making public
local textttttt = game.Workspace.message

script.Parent.MouseButton1Click:Connect(function()
	local MessageData = {
		["content"] = textttttt.Value --This will work because the .Value is part of the function and not the variable
	}
	local DiscordMessageData = HS:JSONEncode(MessageData)
	HS:PostAsync(WebHook, DiscordMessageData)
end)

The reason it works when you do it that way is because, earlier, the textttttt variable only contained the value in the StringValue value during the initialization of that variable in the script.

But if you assign it to the StringValue, and later reference it’s property .Value it will get the current .Value property.

Hello! It’s been 8 months since this post, and I am trying to make an embed discord webhook from roblox for a report system. For some reason I get a bad request error. Was there a roblox-discord webhook cutoff I didn’t know about?

Hello ConsoleWriter,
I believe the code I provided in this thread is still in full affect and is actively working!

Roblox does limit the amount of post requests you can send out, or it could simply be a simple error in your code.

I’d be happy to assist you further in my direct message box, thanks! :heart:

1 Like

Thank you very much. It was an error in my code. I successfully set it up, but do you happen to know how to add an author icon?

Hello there! (You mostlikely found solution for this but still i would like to help) Here is the code

[“avatar_url”] = “imagelink”,