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)
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
}))
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.
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?