Enter Player Username, username gets sent to discord via webook

Hello developers, I am new to scripting, and I was wondering how I could make a system for my Roblox Airline, that Flight Hosts can enter a players username and then press a button then it would send an embedded message through a discord webhook to a channel in discord. Here is my script i’ve got so far!

local webhook = "Webhook here" -- Just put it like that incase anyone wants to try to raid.
local http = game:GetService("HttpService")
local enter = script.Parent.Parent.Enter
local TB = script.Parent
local player = game.GetService("Player")

enter.MouseButter1Click:Connect(function()
	
end)

local unixtime = os.time()
local format = "Sent at %X %Z on %A %d %B"
local timei = os.date(format, unixtime)
--Embedded message
local gotoflight = {
	["content"] = '',
	["embeds"] = {{
		["title"] = "Food Ordering",
		["description"] = "**"..--[[Staff Username]].."** has been to todays flight.",
		["color"] = 15636761,
		["thumbnail"] = {url = "http://www.roblox.com/Thumbs/Avatar.ashx?x=150&y=150&Format=Png&username="..plr.Name},
		["footer"] = {text = timei}
	}}
}
gotoflight = http:JSONEncode(gotoflight)
http:PostAsync(webhook, gotoflight)

The part where it says “–[[Staff Username]]” will be replaced with the local naming of the player.

If anyone is willing to help me with this, please offer some suggestions and let me know how it works if you can, as I am always willing to learn!

1 Like

Did you use a Server or Client sided script?

Client Side script. :slight_smile:

You can’t do http requests from local, use a RemoteEvent and use http on server

Ok, also how can get the players username?

When using a RemoteEvent, you can easily retrieve the username like so.
localscript:

local rs = game:GetService("ReplicatedStorage")
local remote = rs:WaitForChild("YourRemoteEventName")

remote:FireServer(--[[ you can add parameters here if you'd like]])

serverscript:

local rs = game:GetService("ReplicatedStorage")
local remote = rs:WaitForChild("YourRemoteEventName")

remote.OnServerEvent:Connect(function(player, --[[you can receive the parameters you sent from your localscript here]])
-- player is the literal player object, if you'd for example want to print the name, you'd simply do:
print(player.Name)
-- you can then just send the webhook with player.Name filled in where you want the username!
end)

(Here I do assume your remoteEvent is in ReplicatedStorage, if its not, put it there)

Alright, and I assume that i would have to do something like this;

local enter = script.Parent.Parent.Enter
local rs = game:GetService("ReplicatedStorage")
local remote = rs:WaitForChild("StaffAttended")

enter.MouseButter1Click:Connect(function()
	local name = script.Parent.Text
	remote:FireServer(name)
end)

On the client side.

Yes!
Keep in mind on the server you’ll need to do

remote.OnServerEvent:Connect(function(player, name)
-- player is the player who fired
-- name is the variable you sent
end)

This is the server script i’ve just created, can you spot why its not working? As I dont know.

local webhook = "" --Webhook URL goes here
local http = game:GetService("HttpService")
local rs = game:GetService("ReplicatedStorage")
local remote = rs:WaitForChild("StaffAttended")
local unixtime = os.time()
local format = "Sent at %X %Z on %A %d %B"
local timei = os.date(format, unixtime)

remote.OnServerEvent:Connect(function(player, name)
	local data = {
		["content"] = '',
		["embeds"] = {{
			["title"] = "Food Ordering",
			["description"] = "**"..name.."** has gone to the a flight.",
			["color"] = 15636761,
			["thumbnail"] = {url = "http://www.roblox.com/Thumbs/Avatar.ashx?x=150&y=150&Format=Png&username="..plr.Name},
			["footer"] = {text = timei}
		}}
	}
	
	local finaldata = http:JSONEncode(data)
	http:PostAsync(url, finaldata)
end)

And this is the client script.

local enter = script.Parent.Parent.Enter
local rs = game:GetService("ReplicatedStorage")
local remote = rs:WaitForChild("StaffAttended")

enter.MouseButter1Click:Connect(function()
	local name = script.Parent.Text
	remote:FireServer(name)
end)

I will be going off line untill 4pm BST tomorrow, due to school.

You typed Butter instead of Button. :laughing:

As Perdilcarus said, you made a word error in the connection on local, make sure to also enable HTTP requests in game settings, and it should work fine

What I still dont get is how this is the script, I changed the spelling error, turned on HTTP requests and put in the webhook, however it still doesnt work I have 0 idea why it doesnt work.

What doesnt work? The embedded message doesnt go into the discord channel.

Shouldn’t it be http:PostAsync(webhook, finaldata)?
It seems like you’re keeping the webhook url in the variable named ‘webhook’, not ‘url’.

1 Like

Thank you all very much for the help, I really appriciate it!

1 Like