Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my Discord Webhook failing? The API shows that it should be correct!

Hi!

I'm really interested in learning how these Discord webhooks work, it's supposed to be simple where you simply send JSON to a server. I have gotten this to work with a simple script.

local httpService = game:GetService("HttpService")

local data = {
	content = "lamb"
}
local json = httpService:JSONEncode(data)
local location = "https://discordapp.com/api/webhooks/[CENSORED]"

function send()
	httpService:PostAsync(location, json)			
end	

send()

The script above will simply send a message saying 'lamb' to the server.

Now, this is the Discord API reference for the embed here and this is the Discord API reference for the core request.. It shows you how to send requests to Discord and so on..

When I attempt to use this script, it simply doesn't work. It returns error 400 stating that it is a bad request. Is there something wrong with my script or am I doing something wrong with the actual API? You can make fancy messages with the 'embeds' but whenever I attempt to use it, it doesn't work..

local httpService = game:GetService("HttpService")

local data = {
	embeds = {
		title = "aaa"
	}
}
local json = httpService:JSONEncode(data)
local location = "https://discordapp.com/api/webhooks/[CENSORED]"

function send()
	httpService:PostAsync(location, json)			
end	

send()

Any help regarding this script would be extremely helpful. Thanks.

1 comment

0

Heh, I had this problem too. let me help

2 answers

Okay, so I'm using RAW Json.

I'll show you how to:

  • Use embeds
  • Use Variables in Embeds.
local message = [[{
    "username":"]]..plr.Name[[..", -- Here we have the Bot's name, it's running from the Player's name.
    "content": "]]..data.StringContent.Value..[[", -- This is the message the bot sends. [remove if you want]
    "embeds": [{
        "description": "hii", -- Here's the embed description,
        "title": "hiii", --                                                     title,
        "fields":[
        {"name":"hiiii", "value":"hiiiii"}, --                and fields
        {"name":"hiiiiii", "value":"hiiiiiii"}
        ]
    }]
}]]

[Don't use comments in this in real code] To place variables in, use the following

{"name":"]]..variable..[["} -- place two "]", then two "." then the variable, then reverse order [two "." then two "["

If you need any help, contact me on Discord and I'll help you. See my profile.

Here is the right code!

local httpService = game:GetService("HttpService")

local data = {
    embeds = {{
        title = "aaa",
description = "aaa"}} --// change the description to the description of message , description must be there , or else it wont work.
}
local json = httpService:JSONEncode(data)
local location = "https://discord.osyr.is/api/webhooks/[CENSORED]" --[[ 
dont forget to change the censored.. , you know why, 
BTW discordapp.com is not allowed in roblox so you should use discord.osyr.is instead.
and dont forget to set the type
--]] 

function send()
    httpService:PostAsync(location, json,Enum.HttpContentType.ApplicationJSON)           
end 

send()

Hope it helped!!!

This discussion is preserved as it was. New answers, comments, and votes are closed.