I am attempting to make a webhook that sends a request to discord when the player joins, but I keep on coming across an error:
HTTP 401 (Unauthorized)
(Line 24)
Line 24 Code is : http:PostAsync(webhook,http:JSONEncode(data))
I am attempting to make a webhook that sends a request to discord when the player joins, but I keep on coming across an error:
HTTP 401 (Unauthorized)
(Line 24)
Line 24 Code is : http:PostAsync(webhook,http:JSONEncode(data))
Yeah my settings → security is the same as yours.
Can you show us whole code please?
Yeah sure the code is:
local Players = game:GetService("Players")
local http = game:GetService("HttpService")
local webhook = "discord id (i removed it)" --Enter your Webhook link here
Players.PlayerAdded:Connect(function(plr)
local data =
{
["contents"] = "",
["username"] = plr.Name .. " - (#"..plr.userId..")",
["avatar_url"] = "https://www.roblox.com/Thumbs/Avatar.ashx?x=500&y=500&Format=Png&userId="..plr.userId,
["embeds"] = {{
["title"]= plr.name,
["description"] = plr.Name .. " joined the Game",
["type"]= "rich",
["color"]= tonumber(0x6AA84F),
["fields"]={
{
["name"]="Event: Player joined",
["value"]="User: **"..plr.Name.."** with ID: **"..plr.UserId.."** has joined [game](https://www.roblox.com/games/".. game.PlaceId..")/[Profile](https://www.roblox.com/users/"..plr.UserId.."/profile)",
["inline"]=true}}}}
}
http:PostAsync(webhook,http:JSONEncode(data))
end)
Maybe try to get the avatar_url by Enum and not from url.
It says something about the:
http:PostAsync(webhook,http:JSONEncode(data))
part, that it is unauthorized even though HTTP and everything are enabled why is this?
Try this
{
["contents"] = "",
["username"] = tostring(plr.Name) .. " - (#"..tostring(plr.userId)..")",
["avatar_url"] = "https://www.roblox.com/Thumbs/Avatar.ashx?x=500&y=500&Format=Png&userId="..plr.userId,
["embeds"] = {{
["title"]= tostring(plr.name),
["description"] = tostring(plr.Name) .. " joined the Game",
["type"]= "rich",
["color"]= tonumber(0x6AA84F),
["fields"]={
{
["name"]="Event: Player joined",
["value"]="User: **"..tostring(plr.Name).."** with ID: **"..tostring(plr.UserId).."** has joined [game](https://www.roblox.com/games/".. tostring(game.PlaceId)..")\t[Profile](https://www.roblox.com/users/"..tostring(plr.UserId).."/profile)",
["inline"]=true
}
}
}}
}
local load = game:GetService("HttpService")
local Embed = load:JSONEncode({
["contents"] = "",
["username"] = tostring(plr.Name) .. " - (#"..tostring(plr.userId)..")",
["avatar_url"] = "https://www.roblox.com/Thumbs/Avatar.ashx?x=500&y=500&Format=Png&userId="..plr.userId,
["embeds"] = {{
["title"]= tostring(plr.name),
["description"] = tostring(plr.Name) .. " joined the Game",
["type"]= "rich",
["color"]= tonumber(0x6AA84F),
["fields"]={
{
["name"]="Event: Player joined",
["value"]="User: **"..tostring(plr.Name).."** with ID: **"..tostring(plr.UserId).."** has joined [game](https://www.roblox.com/games/".. tostring(game.PlaceId)..")\t[Profile](https://www.roblox.com/users/"..tostring(plr.UserId).."/profile)",
["inline"]=true
}
}
}}
})
load:PostAsync("https://discord.com/api/webhooks/",Embed)
Your issue may be you’re sending a request to an unencrypted endpoint.
Make sure your URL has https
and not http
infront of it.
Also be sure the webhook is still valid on whatever server you got it from, and that its the correct URL format.
No the issue is, he forgot to format it into json which discord reads to turn your embed into a message
I don’t understand the question. Where I put it in the script?
Nevermind. I would delete this question, I was thinking wrong.
I do not believe an option is called “contents”, but rather “content”. When sending post requests in JavaScript, it is called “content”.
contents is right, there is nothing wrong on it,in LUA.
I think the problem is the url of the webhook, maybe it is wrongly copied, I tried the script and it works perfectly.
I also try it, for me it also works perfectly, but I also add a leave log into the script so yeah…
I swear that the Roblox User-Agent was blocked.
Has this been changed?
You can view the structure of an embed here.
It is “content”. I’ll update this with links when I find them.