Discord webhook not working

Hello fellow developers, I’m having an issue with this discord webhook where I’m logging when a player joins this training game and log the chat, as it’s not even sending a message when a player joins/chats, it worked on my own game but not on this one.

Here is some details

  • This is being done in team create.
  • Both HTTP/API service is enabled.
  • The game was published once the script was done.
  • Both webook/discord were made half an hour ago.
  • I’m not the owner of the game
  • I’l getting this error:
    image
local joinsurl  = "https://discordapp.com/api/webhooks/url"
local chaturl = "https://discordapp.com/api/webhooks/url"

local http = game:GetService("HttpService")
-- For when player joins:
game.Players.PlayerAdded:Connect(function(plr)
	local data = {
		["embeds"] = {
			{
				["title"] = "**Player Joined!**",
				["description"] = plr.Name.."#"..plr.UserId.." has joined the game!"
			}
		}
	}
	local finaldata = http:JSONEncode(data)
	http:PostAsync(joinsurl, finaldata)

end)
-- For when player leaves
game.Players.PlayerRemoving:Connect(function(plr)
	local data = {
		["embeds"] = {
			{
				["title"] = "**Player left!**",
				["description"] = plr.Name.."#"..plr.UserId.." has left the game)"
			}
		}
	}
	local finaldata = http:JSONEncode(data)
	http:PostAsync(joinsurl, finaldata)


end)
-- When player chats
game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		local data = { 
			content = "**[.."..player.Name"..]>**"..msg,
                
		}          
		local data = http:JSONEncode(data)
		http:PostAsync(chaturl, data)
	end)
end)
1 Like

Discord is not a logging service :slight_smile: Your code does not consider the rate limits of the API and the staff may delete your webhook and/or terminate your account if you hit the limits frequently.

1 Like

I acknowledge that but this game is only meant for maximum of 3 players each session, and chat is rarely used to our regulations, that’s why I took the choice and made it.
Actually I might delete the chat logger, and keep only joins, it’s just around 3 messages a day or so.

I’m guessing it’s an issue with team create. Try testing in a solo place and running the script.

Also, it’s still not a logging service and an exploiter could take advantage of the unregulated http requests and make a lot of bots join and leave.

Only people with a certain rank in our group can join the game, also tried what you said and didn’t work, I assume I need to wait some time, I asked a friend and he said this forbidden error is happening in some studios.

I searched for the meaning of 403 when posting to a webhook and it could mean that the webhook is no longer valid, the data being passed is not formatted properly or discord blocked the webhook.

I don’t see how data isn’t being passed or not formatted properly, this is my code:

local joinsurl  = "https://discordapp.com/api/webhooks/url"
local http = game:GetService("HttpService")
-- For when player joins:
game.Players.PlayerAdded:Connect(function(plr)
	local data = {
		["embeds"] = {
			{
				["title"] = "**Player Joined!**",
				["description"] = plr.Name.."#"..plr.UserId.." has joined the game!"
			}
		}
	}
	local finaldata = http:JSONEncode(data)
	http:PostAsync(joinsurl, finaldata)

end)
-- For when player leaves
game.Players.PlayerRemoving:Connect(function(plr)
	local data = {
		["embeds"] = {
			{
				["title"] = "**Player left!**",
				["description"] = plr.Name.."#"..plr.UserId.." has left the game)"
			}
		}
	}
	local finaldata = http:JSONEncode(data)
	http:PostAsync(joinsurl, finaldata)
end)

I just tested your code and there’s nothing wrong with it. So I’ll assume it’s either of these two:

1 Like

Very thankful for this info, appreciate it. However I been trying alot of stuff but none is working.