Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

HTTP 400 (Bad Request) What are reasons for this error to be thrown? Discord Webhook.

Asked by
appxritixn 2235 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Alright, so here is what I know for sure:

• I have the correct URL

• All of the arguments in the function are correct.

• I am not new to the Roblox development world, and have done things similar to this before.

Some basic information: This is a request to go directly from Roblox to a Discord webhook.

This is a function which I am trying to call every time a player submits a report in my game. Regardless of how much time I give in-between calls, this function throws the error "HTTP 400 (Bad Request)".

Here is the function:

local function REPORT_TO_DISCORD(player,target,reason)
    local result,err = pcall(function()
        local url = "REDACTED"
        local report_base = [[
            **Username:**   [%s](https://www.roblox.com/users/%s/profile) (%s)
            **Reported:**   %s
            **Reason:** %s
            **Game:**   [%s](https://www.roblox.com/games/%s/Game)
        ]]
        local embed = {}
        embed.timestamp = getCurrentTime()
        embed.description = {
            report_base:format(
                player.Name or "N/A",
                player.UserId,
                player:GetRoleInGroup(3587367) or "N/A",
                target or "N/A",
                reason or "N/A",
                game:GetService("MarketplaceService"):GetProductInfo(game.PlaceId).Name,
                game.PlaceId
            )
        }
        embed.footer = {
            icon_url = "",
            text = "Report Log"
        }
        embed.thumbnail = {
            url = game.Players:GetUserThumbnailAsync(
                player.UserId,
                Enum.ThumbnailType.AvatarBust,
                Enum.ThumbnailSize.Size420x420
            )
        }
        embed.author = {
            name = player.Name,
            url = "https://www.roblox.com/users/" .. player.UserId .. "/profile",
            icon_url = game.Players:GetUserThumbnailAsync(
                player.UserId,
                Enum.ThumbnailType.HeadShot,
                Enum.ThumbnailSize.Size420x420
            )
        }

        local HookData = {username = player.Name, avatar_url = game.Players:GetUserThumbnailAsync(player.UserId,Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size420x420), embeds = {embed}}
        HookData = http:JSONEncode(HookData)

        http:PostAsync(url, HookData)
    end)
    if not result then
        warn(err)
    end
end

EDIT: Redacted the URL, and deleted the webhook.

I know some of the possible reasons for "HTTP 400 (Bad Request)" being thrown, however, there is always something new to learn.

Hopefully an answer to this query can help me and many others,

  • oCrxptic

EDIT 2: I found another way of accomplishing this, however, if someone can provide an answer that would still help others.

0
you shouldn't put webhook urls in public, people can spam your bot and potentially get you banned from discord for not respecting their rate limits Elyzzia 1294 — 4y
1
you shouldn't put webhook urls in public, people can spam your bot and potentially get you banned from discord for not respecting their rate limits Elyzzia 1294 — 4y
1
I forgot to do that before I posted. Thanks for the reminder! appxritixn 2235 — 4y
0
Do you have HTTP services enabled in your place? WideSteal321 773 — 4y
1
Yes appxritixn 2235 — 4y

1 answer

Log in to vote
1
Answered by 3 years ago

I would say that the reason for this is because the information being transmitted to Discord is invalid, or the formatting is invalid.

I would double check the formatting to ensure that everything is as it should be.

Ad

Answer this question