Making a button that will have a Webhook send a message to discord

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to create a GUI button that when pressed it will send a specific message to discord via webhook.

  2. What is the issue? Include screenshots / videos if possible!
    As of right now I have a script in workspace where if you join the game, a message will be sent to discord. But I can’t figure out how a message can be sent using a TextButton

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried finding solutions on both YouTube and DevFourm, I attempted any that seemed reliable to me but none worked. Besides that I tried to solve the issue myself by trying to put the script in the button and rewriting some of the script but still didn’t work.

Here is my current script located in workspace where if a player join a message will be sent

local url = "https://discord.com/api/webhooks/832756049986584607/MIFihgs5Rs-uyIbnH8Lv3eRH8U1nU60Jppyq3nNBoGfTByUEVOd00q0t6vqDgLFWI8sN"
local http = game:GetService("HttpService")

game.Players.PlayerAdded:Connect(function()
	local data = {
		['embeds'] = {{
			['title'] = "**Assistance required**",
			['description'] = "A player has requested assistance, please join the game."
		}}
	}
	
	local finaldata = http:JSONEncode(data)
	http:PostAsync(url, finaldata)
end)

Any help would be appreciated.

You could add a LocalScript, and if you already have your TextButton set up you can parent the script there :thinking: This can be done with a MouseButton1Down event I believe & using a RemoteEvent in ReplicatedStorage you can detect for the change when the Player hits the button:

--Client Script Parented in the TextButton
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local Button = script.Parent

Button.MouseButton1Down:Connect(function()
	Event:FireServer()
end)
--Your Other Script
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local url = "https://discord.com/api/webhooks/832756049986584607/MIFihgs5Rs-uyIbnH8Lv3eRH8U1nU60Jppyq3nNBoGfTByUEVOd00q0t6vqDgLFWI8sN"
local http = game:GetService("HttpService")

Event.OnServerEvent:Connect(function(Player)
	local data = {
		['embeds'] = {{
			['title'] = "**Assistance required**",
			['description'] = "A player has requested assistance, please join the game."
		}}
	}
	
	local finaldata = http:JSONEncode(data)
	http:PostAsync(url, finaldata)
end)

Thanks for the reply, I’m pleased to say it worked! Thanks so much.

1 Like