Webhook issues with ModuleScript

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

Have my module send the webhook

  1. What is the issue? Include screenshots / videos if possible!

The module is unable to send the webhook, even though it passes the pcall and no errors are in console.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

pcall, retyped everyting to ensure no typos, DevHub

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Hello DevForum,

For some reason, the following code works fine:

Http:PostAsync(game:GetService("ServerStorage"):GetAttribute("ADMINCI_WH_URL_MAIN"), 
		Http:JSONEncode({
			username = "AdminCI debug",
			embeds = {
				{
					title = "Debug message",
					description = "This is AdminCI debug content, sent through a manual Http post at <t:" .. os.time() .. ">.",
					footer = {
						text = "Copyright (c) Quackoramic. All rights reserved."
					},
					color = dub
				}
			}
		}),
		Enum.HttpContentType.ApplicationJson,
		false
	)

But the following code does not:

local service = {}

function service:send(username, title, description, color)
	local Http = game:GetService("HttpService")

	local red = 16731469
	local gre = 5898061
	local blu = 5086719
	local dub = 15132390

	local success, response = pcall(function()
		Http:PostAsync(game:GetService("ServerStorage"):GetAttribute("ADMINCI_WH_URL_MAIN"), 
			Http:JSONEncode({
				username = username,
				embeds = {
					{
						title = title,
						description = description,
						footer = {
							text = "Copyright (c) Quackoramic. All rights reserved."
						},
						color = color
					}
				}
			})
		)
	end)
	
	if success then
		warn("Request successful")
		print(response) -- This will contain the response from the server
	else
		warn("Error: " .. response) -- This will contain the error message
	end

end

return service

-- webhook:send("AdminCI debug 2", "Debug message 2", "This is AdminCI debug content 2, sent through WebhookService at <t:" .. os.time() .. ">.", "dub")

The bottom line of the code is what I am running to attempt to send the webhook.
Yes, the first one works, so the issue is not my webhook URL. I am so confused…
Also, I am definitely calling the ModuleScript right, I can guarantee that.

I hope that someone can figure out why I can’t :sweat_smile:

Thank you in advance,
Swiss

When you say it does not, do you mean that it is getting neither a success nor an error?

Hello, it says that it was successful, and the response is just nil. However, the webhook is never sent.

What actually is the URL? If it is straight to discord then I think those got blocked

It’s not straight to Discord, and as mentioned, the first codeblock where I just send the Http request manually does work. It only doesn’t work through the module script.

Replace the colon with a dot I just want to rule something out

function service:send() should work as well as service.send = function() but I’ll check it out in a couple of minutes when I turn my PC on :slight_smile:

1 Like

Just realised why:
image
You have to add return in front of the Http:PostAsync, so that the value of response is set

1 Like

Thanks for that, now it’s telling me that it’s giving HTTP 400 bad request. I’m guessing my formatting must be wrong somewhere…

Edit: I cannot figure out for the life of me what is formatted wrong. It should all be working fine.

Print out what is being encoded, and check that everything looks correct that way

2 Likes

That’s looking all magnificent.

1 Like

NEVERMIND!! For some reason, there is an error with the colors. I think I know how to fix it. Thank you all so much for the help! <3
I’m gonna mark Poppy’s post as solution.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.