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

Why is this not working? (Discord Webhook Related)

Asked by 5 years ago

Note: I'm making a GUI Voting System. So basically, when the player clicks the TextButton, it will send a message with the player's username. But it dosen't work. Please check my script.

    script.Parent.MouseButton1Click:connect(function(plr)

    local http = game:GetService("HttpService")

local Data = {

["content"] = plr.Name, "Voted for PRR"

}



Data = http:JSONEncode(Data)



http:PostAsync("https://discordapp.com/api/webhooks/566241492218282018/ITWAhltgl-c_fy7whA8b2uhDYthnjWPV4z_60K5pVX7MTrIvPTsqrIHq6lh67ONn0sCH", Data)

end)
0
You should delete the webhook link since it is private and can be abused by others. JakyeRU 637 — 5y
0
^ starmaq 1290 — 5y

1 answer

Log in to vote
2
Answered by
JakyeRU 637 Moderation Voter
5 years ago
Edited 5 years ago

Hello. You should NOT use Discord for logging. But here I fixed your code.

-- LocalScript
local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    local Data = {
        ["content"] = Player.Name.. " voted for PRR!"
    }
    game.ReplicatedStorage.SendPost:FireServer(Data)
end)

///

-- ServerScript
local HttpService = game:GetService("HttpService")

local URL = "https://discord.osyr.is/your webhook here"



game.ReplicatedStorage.SendPost.OnServerEvent:Connect(function(player, data)

HttpService:PostAsync(URL,HttpService:JSONEncode(data))

end)

So, the Client cannot send HttpRequests. You will use a Remote Event to send the data from the client to the server. The server will send the data. In the first code, the data will be sent to the server through the remote event when the player clicks the TextButton / ImageButton.

In the second script, as you can see, I used https://discord.osyr.is instead of https://discordapp.com since Discord does not allow that. So you have to use a webserver. Some information about osyr: Click Me After the data is received from the Remote Event, the Server will send it to Discord. And here is the result: !Result

0
yah pretty much, i like that you spent your time making a bot too xd starmaq 1290 — 5y
Ad

Answer this question