Discord Webhook Support

Trying to make a system where when a player fires a taser it sends a webhook to discord. When I run it nothing happens.

local Tool = script.Parent
local url = "https://discordapp.com/api/webhooks/"
local http = game:GetService("HttpService")

if Tool.Deployed.Value == true then
    	local data = {
    		['embeds'] = {{
    		    ['title'] = "Taser Fired",
    		    ['description'] = plr.Name .. " Has Fired His Taser."
    		    
    		    }}
    	}
    		
    	local finaldata = http:JSONEncode(data)
        http:PostAsync(url, finaldata)

    end

You only checked the Deployed bool value once, which then the check stops, and that code will never run, what you want to do is to instead connect it to either the Activated event of the tool or the Changed property of the bool value.

Please note that over sending message to Discord through webhook can result in your discord account being banned.

Also, that is only one of the cases, I don’t know if it is related to client/server replication or something.

2 Likes
Tool.Activated:connect(function()
--webhook here

No, thats an event, that should not be inside an if statement

Tool.Activated:Connect(function()
   --add your webhook code here
end)

This

local Tool = script.Parent;

local url = "https://discordapp.com/api/webhooks/"
local http = game:GetService("HttpService")

Tool.Activated:connect(function()
	local data = {
	['embeds'] = {{
	    ['title'] = "Taser Fired",
	    ['description'] = plr.Name .. " Has Fired His Taser.",
	    ['content'] = "LOL"
	    }}
}

	local finaldata = http:JSONEncode(data)
    http:PostAsync(url, finaldata)

end)

Still not working, isn’t doing anything

have you set the URL to the webhook link?

also that end must have a closure bracket )
end)
because it is wrapped in the :Connect() function and ) in the end is basically the closing bracket of connect.

Yeh, I set the webhook as the link, And changed the end to a bracket still isn’t working

You have to use a ServerScript I found out that you can’t send an Https request from a local script because it will error this out.

Screenshot_5

Added it to a server script same result

you don’t just add it to the serverscript, you have to configure it especially when you can’t easily get the player from the serverscript.

I suggest using a remote event to replicate your mouse click to the server,
it works for me!

also, it doesnt work because you forgot something most important, the content.

local data = {
		['embeds'] = {{
		    ['title'] = "Taser Fired",
		    ['description'] = plr.Name .. " Has Fired His Taser.",
		    ['content'] = "LOL"
		    }}
	}

content is the vital thing in sending a message to discord, without it, it will automatically cancel your message

Are you able to post the script you used

local Tool = script.Parent;

local url = "https://discordapp.com/api/webhooks"
local http = game:GetService("HttpService")

Tool.Activated:connect(function()
	local data = {
		['embeds'] = {{
		    ['title'] = "Taser Fired",
		    ['description'] = plr.Name .. " Has Fired His Taser.",
		    ['content'] = "LOL"
		    }}
	}
		
	local finaldata = http:JSONEncode(data)
    http:PostAsync(url, finaldata)

end)

is the one I tried but still isnt working

1 Like

Add a debounce, if you spam click the the tazer that means it’ll spam webhooks.

Keep in mind the Discord webhook limit is 30 messages per minute, if you go over that limit you risk your Discord account getting banned.

Source: https://twitter.com/lolpython/status/967621046277820416

That guy works at Discord.

2 Likes
local Tool = script.Parent

local url = "https://discordapp.com/api/webhooks"
local http = game:GetService("HttpService")

Tool.Activated:connect(function()
	local data = {
		['embeds'] = {{
		    ['title'] = "Taser Fired",
		    ['description'] = plr.Name .. " Has Fired His Taser.",
		    ['content'] = "LOL"
		    }}
	}
		
	local finaldata = http:JSONEncode(data)
    http:PostAsync(url, finaldata)

end)

try this, I removed the “;”

Have you turned on http requests in game settings?

PLEASE note that Discord webhooks should not be used as a logging service. You risk getting both your account and server banned, and, in a worst-case scenario, end up getting the Roblox user-agent blacklisted by Discord AGAIN (this has happed a few years ago as a result of API abuse originating from Roblox).
You should instead look into hosting your own logging service or use one such as Loggly. Don’t ruin it for the rest of us :blush: