How can I make a command sends embeds to the discord by a webhook?

Greetings Developers,
How can I make a command sends embeds to the discord by a webhook?

1 Like

You are going to need the HttpService to do this. Specifically, you need to make a POST request to your webhook by using HttpService:PostAsync.

1 Like

I tried that but it doesn’t work!

How did it not work? You should show your attempt (but omitting the webhook, of course)

2 Likes

Main Scipt:

local remote = Instance.new("RemoteEvent", game.ReplicatedStorage);
remote.Name = "SendToDiscord"
function SendToDiscord(msg)
    local http = game:GetService("HttpService")
    local Data = {
        ["content"] = msg
    }
    Data = http:JSONEncode(Data)
    http:PostAsync("https://discord.com/api/webhooks/LINK", Data)
end

remote.OnServerEvent:connect(function(player) 
	SendToDiscord('@here '..player.Name..' Just started a Training Session at the Training Center! Click the Link here if you would like to join.   https://www.roblox.com/games/'.. game.PlaceId)
end)

Fire Event:

local rep = game.ReplicatedStorage
local GroupID = 6419782
local MinRank = 16

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:connect(function(msg)
		if string.lower(msg) == "!training" and plr:GetRankInGroup(GroupID) >= MinRank then
			rep.SendToDiscord:FireAllClients()
		end
	end)
end)

You don’t need a remote for this.

You can just send the POST request in the if block.

But, how…?
…

if string.lower(msg) == "!training" and plr:GetRankInGroup(GroupID) >= MinRank then
    SendToDiscord('@here '..player.Name..' Just started a Training Session at the Training Center! Click the Link here if you would like to join.   https://www.roblox.com/games/'.. game.PlaceId)
end

You would copy over your function to the PlayerAdded script.

1 Like

Okay, Thank you!..

OMG, Still doesn’t work!

local rep = game.ReplicatedStorage
local GroupID = 6419782
local MinRank = 16
local WebhookID = "https://discord.com/api/webhooks/" 

function SendToDiscord(msg)
    local http = game:GetService("HttpService")
    local Data = {
        ["content"] = msg
    }
    Data = http:JSONEncode(Data)
    http:PostAsync(WebhookID, Data)
end

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:connect(function(msg)
		if string.lower(msg) == "!training" and plr:GetRankInGroup(GroupID) >= MinRank then
			rep.OpenTraining:FireAllClients()
			SendToDiscord('@here '..plr.Name..' Just started a Training Session at the Training Center! Click the Link here if you would like to join.   https://www.roblox.com/games/'.. game.PlaceId)
		end
	end)
end)

--// Abd_Dev

Remove the OpenTraining remote.

And that too.

Why?..

Oh never mind. Thought it was the “SendToDiscord” remote.

What’s the wrong in my script?

IIRC roblox banned the discord URL with HttpService(might be wrong), try using a proxy instead and it might work.