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

Webhook isn't working at all, no errors appearing in console?

Asked by 5 years ago
Edited 5 years ago

Basically, I'm trying to make a webhook that will send all messages being sent in my roblox game to a channel in my discord server

(you may think this would be API abuse but I don't plan to have any more than 10 people in the game at once)

I think the problem could be the variables, but I'm not entirely sure, I'm a bit of a noobie with API.

**The code: **

game.Players:FindFirstChild().Chatted:Connect(function(msg)
    local text = msg
    local user = game.Players.LocalPlayer.Name
local http = game:GetService("HttpService")
local Data = {
    ["content"] = "`"..text.."`",
    ["username"] = user,
}

Data = http:JSONEncode(Data)

http:PostAsync("*webhook link redacted.*", Data) 
end)

0
is HttpEnabled set to true? SteamG00B 1633 — 5y
0
yes, it is JamiethegreatQ777 16 — 5y
0
I'm not familiar with discord's API, but are you certain that they use JSON and not some other format? SteamG00B 1633 — 5y
View all comments (4 more)
0
To me, that code looks fine, my guess is something on the other end is wrong. SteamG00B 1633 — 5y
0
im pretty sure they use json JamiethegreatQ777 16 — 5y
0
Ok, well in the [REDACTED] webhook link, do they give you a custom webhook link or is it some generic one with a key they give you? SteamG00B 1633 — 5y
0
its a generic one thats given to me, i could send you the link if you got discord, my tag is Koyoka#2464 JamiethegreatQ777 16 — 5y

1 answer

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
5 years ago
Edited 5 years ago

There was nothing wrong with any of the http stuff, just a simple mistake with finding the first player, and also no getting a LocalPlayer from a server script:

game.Players.ChildAdded:Wait()
local player = game.Players:FindFirstChildOfClass("Player")
player.Chatted:Connect(function(msg)
    local text = msg
    local user = player.Name
    local http = game:GetService("HttpService")
    local Data = {
        ["content"] = "`"..text.."`",
        ["username"] = user,
    }
    Data = http:JSONEncode(Data)
    http:PostAsync("", Data) --Put the link you saved between the two quotes.
end)
Ad

Answer this question