Help with Discord Logs

I want it to make it so where it sends the log of the players text into discord.

It won’t send for some reason, no error.

I’ve tried changing up the script, nothing worked, one time it gave me an error, but I fixed it.

Can anyone help, please and thank you!

local http = game:GetService("HttpService")
local WebhookURL = "https://discordapp.com/api/webhooks/redacted"
  
game.StarterGui.ApplicationGui.ApplicationMainFrame.SubmitButton.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(question1a,question2a,question3a,question4a,question5a,question6a)
        local plr = game.Players.LocalPlayer
        if plr ~= nil then
            local question1a = game.StarterGui.ApplicationGui.ApplicationMainFrame.Question1.Text
            local question2a = game.StarterGui.ApplicationGui.ApplicationMainFrame.Question2.Text
            local question3a = game.StarterGui.ApplicationGui.ApplicationMainFrame.Question3.Text
            local question4a = game.StarterGui.ApplicationGui.ApplicationMainFrame.Question4.Text
            local question5a = game.StarterGui.ApplicationGui.ApplicationMainFrame.Question5.Text
            local question6a = game.StarterGui.ApplicationGui.ApplicationMainFrame.Question6.Text
            local firstData = {
                ['username'] = "Application Log",
                ['content'] = plr.."applied for "..question1a..", "..question2a..", "..question3a..", "..question4a..", "..question5a..", "..question6a.."."
            };
            local secondData = http:JSONEncode(firstData)
            http:PostAsync(WebhookURL,secondData)
        end
    end)
end)
4 Likes

I am not too experienced with discord, but I am pretty sure you should not expose your webhook URL like that, snip it out of your code, and take the video down for your own safety please!

1 Like

Put in a local script and parent it to the gui. Then change game.StarterGui to script.Parent. While this should work I believe it is against Discord’s terms and service to log but I’m not sure

1 Like

Okay, let me try that, thank you.

No it still doesn’t work for some reason, still no error.

Listening to a MouseButton1Click from StarterGui will never work, you need to listen to it from the player’s PlayerGui.

This needs to be in a server script, to my knowledge you can’t use any aspect of HTTPService from the client, even if you can it is not recommended (your discord webhook link will be leaked)

Why listen for a remote event if you are just going to distinguish via a MouseButton1Click anyway?

To summarize:
Listen to the MouseButton1Click through a LocalScript inside of the text button and fire a remote event using a script like:

script.Parent.MouseButton1Click:Connect(function()
   game.ReplicatedStorage.RemoteEvent:FireServer(--[[Parameters]])
end)   

Then use a serverscript to detect that and fire the webhook:

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player,--[[parameters]])
-- send webhook
end)

Hopefully this is able to squash your bugs.

2 Likes

What do I put in

   game.ReplicatedStorage.RemoteEvent:FireServer(--[[Parameters]])

What do I put in the --[[Parameters]]) part?

The information you are trying to send through the webhook, which I assume is the “question1a, question2a” etc.

I highly recommend AGAINST running an (apparent) application system through Discord though, seeing-as Discord has a 2,000 character limit which you can’t exceed. Big vouch for a Trello application system in the long run.

It still doesn’t work :frowning: https://gyazo.com/bffd005259dc1e365dce9fcf26debe9d

I had made a discord tutorial on Webhooks a while ago, it might be helpful in this case.

Also ensure that your Http Services are turned on in the game settings

This is what I used for my Feedback UI

Client side

local db = false
feedbackMain.SendButton.MouseButton1Click:Connect(function()
	if not db and maxCharacters - #feedbackMain.InputBox.Input.Text >= 0 then
		db = true
		local msg = feedbackMain.InputBox.Input.Text
		feedbackMain.InputBox.Input.Text = "Sending Message..."
		local response = game.ReplicatedStorage.FilteringFunction:InvokeServer(msg)
		feedbackMain.InputBox.Input.Text = response
		wait(5)
		if feedbackMain.InputBox.Input.Text == response then
			feedbackMain.InputBox.Input.Text = "Type feedback/bug report here"
		end
		db = false
	end
end)

The above code basically will first check if the Characters are not more than max characters and then Invoke the Filtering function in Replicated Storage, btw i didnt show you the variable above I assume you know how to do it.

local webhookURL = "https://discordapp.com/api/webhooks/xxxx/xxxxxxx"
local filteringFunction = game.ReplicatedStorage.FilteringFunction

local ChatService = game:GetService("Chat")

local HTTP = game:GetService("HttpService")

function filteringFunction.OnServerInvoke(player, msg)
	local FilteredMessage = ChatService:FilterStringForBroadcast(msg, player)	
        --Filter the message, before sending it to the webhook.

	local payload = HTTP:JSONEncode({
		content = FilteredMessage,
		username = "Submitted By "..player.Name
	})
	
	HTTP:PostAsync(webhook, payload)
	return "Feedback recieved!"
end

That code should be in Server Side, so most likely in the ServerScriptService. The above code takes the argument that was passed on to the function and then stores the filtered message in payload and then posts a Http Request to the webhook with the Payload we have in JSON format.

Okay thank you, cya later have a nice day, Bye, cya!

You need to filter the text you’re receiving from the user, or your game could be taken down.

Yes, Sir. Thank you, alright have a nice day!

So I followed your tutorial, but some part of it had an error, and that was the content part!

local HS = game:GetService("HttpService")
local WebhookURL = "https://discordapp.com/api/redatced
local SubmitButton = script.Parent.SubmitButton
--Replace your link with the link in the Quotes.

SubmitButton.MouseButton1Click:Connect(function(Player,Question1A,Question2A,Question3A,Question4A,Question5A,Question6A)
	local Player = game.Players.LocalPlayer
	local Question1A = script.Parent.Question1
	local Question2A = script.Parent.Question2
	local Question3A = script.Parent.Question3
	local Question4A = script.Parent.Question4
	local Question5A = script.Parent.Question5
	local Question6A = script.Parent.Question6
	local MessageData = {
		["content"] = Player.."Has applied for, "..Question1A..", "..Question2A..", "..Question3A..", "..Question4A..", "..Question5A..", "..Question6A.."."
	}
	MessageData = HS:JSONEncode(MessageData)
--We used JSONEncode to convert the Lua Table into a Json String 
	HS:PostAsync(WebhookURL,MessageData)
end)

18:01:06.199 - Players.Diguard.PlayerGui.ApplicationGui.ApplicationMainFrame.Script:14: attempt to concatenate local ‘Question5A’ (a userdata value)

Wait the script doesn’t look at the right place, what i meant to say is fire a remote function from the client side and handle the HttpRequest in server side script

Oh crap, someone just took my API and spammed “KFX then the N word with a nude picture” I am so god dang mad right now, I’m so stupid, he’s going to get me banned. And also, where do I put the script?

But he wasn’t successful because it was only me in the discord :slight_smile:

Oof, be sure to hide your link. This is what you probably want to do

In starter gui, localscript

 local plr = game.Players.LocalPlayer

plr.PlayerGui.ApplicationGui.ApplicationMainFrame.SubmitButton.MouseButton1Click:Connect(function()
       
            local question1a = game.StarterGui.ApplicationGui.ApplicationMainFrame.Question1.Text
            local question2a = game.StarterGui.ApplicationGui.ApplicationMainFrame.Question2.Text
            local question3a = game.StarterGui.ApplicationGui.ApplicationMainFrame.Question3.Text
            local question4a = game.StarterGui.ApplicationGui.ApplicationMainFrame.Question4.Text
            local question5a = game.StarterGui.ApplicationGui.ApplicationMainFrame.Question5.Text
            local question6a = game.StarterGui.ApplicationGui.ApplicationMainFrame.Question6.Text

        local Function = game:GetService("ReplicatedStorage").SendFunction

Function.InvokeServer(plr, question1a, question2a, question3a, question4a, question5a, question6a)
end)

Make another script in ServerScripts which contains the following

local webhookURL = "https://discordapp.com/api/webhooks/xxxx/xxxxxxx"
local filteringFunction = game.ReplicatedStorage.FilteringFunction

local ChatService = game:GetService("Chat")

local HTTP = game:GetService("HttpService")

function filteringFunction.OnServerInvoke(player, question1a, question2a, question3a, question4a, question5a, question6a)

local msg = plr.Name.." Has applied for, "..Question1A..", "..Question2A..", "..Question3A..", "..Question4A..", "..Question5A..", "..Question6A.."."


	local FilteredMessage = ChatService:FilterStringForBroadcast(msg, player)	
        --Filter the message, before sending it to the webhook.

	local payload = HTTP:JSONEncode({
		content = FilteredMessage,
		username = "Submitted By "..plr.Name
	})
	
	HTTP:PostAsync(webhook, payload)
	return "Application Received"
end

Also havent tested the code as i am on mobile, there might be some errors.

1 Like

Ah, Okay error is SendFunction is not there nor is Invoke server, what do I do with those?

I didnt quite understand what you said