My discord webhook doesn't work

Heya guys, i wanted to known if you can help

I keep getting some issues with my discord webhook, i found already where the issues is but went to known why.

Here is the issues:

image

Which programming language are you using?

It’s on roblox studio so it’s lua

You’re missing the second argument in the table.concat. Example table.concat(table,” “)

Further Reference: What is table.concat() actually do? - #2 by TheCarbyneUniverse

1 Like

Oops my bad, wait i’m gonna try

I changed my code to

image

But still error 400 bad request :confused:

Can you show all of your code?

1 Like

Yes no problem there

function discrpc.new(getcontent, getcolor, whkurl, field1Name, field1Val, field2Name, field2Val, field3Name, field3Val, field4Name, field4Val, field5Name, field5Val)
	
	local getfields = {}
	
	--
	
	if field1Name ~= nil then
		table.insert(getfields, '{\n["name"] = '..tostring(field1Name)..',\n["value"] = '..tostring(field1Val)..',\n["inline"] = false\n}')
	end
	
	if field2Name ~= nil then
		table.insert(getfields, '\n{\n["name"] = '..tostring(field2Name)..',\n["value"] = '..tostring(field2Val)..',\n["inline"] = false\n}')
	end	

	if field3Name ~= nil then
		table.insert(getfields, '\n{\n["name"] = '..tostring(field3Name)..',\n["value"] = '..tostring(field3Val)..',\n["inline"] = false\n}')
	end

	if field4Name ~= nil then
		table.insert(getfields, '\n{\n["name"] = '..tostring(field4Name)..',\n["value"] = "'..tostring(field4Val)..',\n["inline"] = false\n}')
	end
			
	if field5Name ~= nil then
		table.insert(getfields, '\n{\n["name"] = '..tostring(field5Name)..',\n["value"] = '..tostring(field5Val)..',\n["inline"] = false\n}')
	end
	
	--
	
	wait(.1)
	
	--

	local data = {
		["content"] = tostring(getcontent),
		["embeds"] = {{
			["title"] = "Roblox Test",
			["description"] = "Test ..",
			["type"] = "rich",
			["color"] = getcolor,
			["fields"] = {
				table.concat(getfields, ", ")
			},
		}}
	}

	if whkurl ~= nil then
		local newdata = HttpServ:JSONEncode(data)
		HttpServ:PostAsync(whkurl, newdata)
	else
		error("Umm, something wrong with your webhook url, not entered? mispell?")
	end
end

Error code 400 is the error when the server doesn’t understand what your post mean.

Maybe, wrong Json?

1 Like

Do you need what i do when i fire the function?

It’s not the game’s server error, it’s webhook’s server error.

1 Like

So it is from discord or roblox?

It’s from discord, you basically send wrong json.
Read discord’s webhook documentation. Maybe.

1 Like

There my script i use to fire the function

local api = require(script.DiscordApi)

api.new(
	"Testing",
	Color3.new(27, 145, 248),
	whkurl,
	"UserId",
	p.UserId,
	"Game Place",
	"https://roblox.com/games/"..game.PlaceId.."/Toxic-Tycoon",
	"Game Creator",
	gs:GetGroupInfoAsync(7087080).Owner.Name,
	"Joined?",
	"`True`"
)

I’m not using this module, tough. I’m not sure.

1 Like

I made the module lol, but the problem is the table.concat with the fields section :confused:

If i do

local data = {
    ["content"] = tostring(getcontent),
    ["embeds"] = {
        {
            ["title"] = "Roblox Test",
            ["description"] = "Test ..",
            ["type"] = "rich",
            ["color"] = getcolor,
            ["fields"] = {
                {
                    ["name"] = "Test",
                    ["value"] = "Yep it work",
                    ["inline"] = false
                }
            }
        }
    }
}

if whkurl ~= nil then
    local newdata = HttpServ:JSONEncode(data)
    HttpServ:PostAsync(whkurl, newdata)
else
    error("Umm, something wrong with your webhook url, not entered? mispell?")
end

Without table.concat it work, but i need to find out how to fix the table.concat :confused:

Strange. Have you tried iterating through the getfields array and adding it to the data?

local data = {
		["content"] = tostring(getcontent),
		["embeds"] = {{
			["title"] = "Roblox Test",
			["description"] = "Test ..",
			["type"] = "rich",
			["color"] = getcolor,
			["fields"] = {
			},
		}}
	}

for i,v in pairs(getfields) do 
table.insert(Data["embeds"]["fields"], v)
end

--post the embed
1 Like

i think it’s because of the color, you can’t pass a color3 value

u could just pass 1 string of the color3 value and do some string manipulation to check whenever the new color appears

like “255:255:255” or “255,255,255”

edit: nvm i just read the comments!

1 Like

I’ll try thank you for your answer :smiley:

I got an error:

image