Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Discord Webhook script not getting past the first line?

I have a script that sends a message to a discord channel, the Webhook part works just fine and sends messages but it isn't working now, I am checking to see if a bool is true and if so then send the message with a given Username and Message, the Message part that is sent from a Localscript works successfully but the Server script does not, I set up a few prints and it doesn't get past the very first one.


if game.Workspace.BoolValue.Value == true then
	print("BoolValue is True")
	


local url = "https://discordapp.com/api/webhooks/291973926093848578/3JBUcZ6sStsGQ0MOdWey4oSIw11opaEPga_vw1H2MiWWimaM4vs4B44l9H7W353NkpTd" 
local http = game:GetService("HttpService")
if http.HttpEnabled == true then
	print("Http is True")
end
local HookData = {
['username'] = game.Workspace.Username, 
['content'] = game.Workspace.Message
}
HookData = http:JSONEncode(HookData)
wait(0.4)
http:PostAsync(url, HookData) 


        
wait (0.01)

game.Workspace.BoolValue = false

 end


There is no error from the output what so ever,

This next script works perfectly fine but I will give it to you as all of the information I have will help debug this script

local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent
 

local textBox = Instance.new("TextBox")
textBox.Parent = screenGui
textBox.Position = UDim2.new(0, 700, 0, 300)
textBox.Size = UDim2.new(0, 150, 0, 50)
textBox.BackgroundColor3 = BrickColor.White().Color
textBox.Text = "Type Your Message Here"



 textBox.FocusLost:connect(function(enterPressed)
	
	if enterPressed == true then
		
		game.Workspace.Message.Value = textBox.Text
		game.Workspace.Username.Value = game.Players.LocalPlayer.Name
		game.Workspace.BoolValue.Value = true
	end
	end)

	


1 answer

It seems that problem is that you check the bool value only once, when the script runs. At that moment the bool value obviously is still false, so everything works just fine. You would have to connect changed event to the bool value, if you want it to be called each time the bool value is changed.

game.Workspace.BoolValue.Changed:connect(function(value)
  if value then
    print("BoolValue is True")



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

    -- Also, these had missing .Value property    vvvv
    local HookData = {
      ['username'] = game.Workspace.Username.Value, 
      ['content'] = game.Workspace.Message.Value
    }
    HookData = http:JSONEncode(HookData)
    wait(0.4)
    http:PostAsync(url, HookData) 



    wait (0.01)

    game.Workspace.BoolValue.Value = false
  end
end)

This should now work, but there is a huge flaw in this script. It will only work in games, that have filtering disabled, which is not nice at all. I suggest using remote events, instead of relaying on a silly bool value. Besides, it would be much cleaner, since you'll pass the message directly to the script, instead of using another value.

So your new setup would look like:

Put a RemoteEvent in ReplicatedStorage and name it "DiscordEvent".

Server script

game.ReplicatedStorage.DiscordEvent.OnServerEvent:connect(function(player, message)
  if message then
    local url = "https://discordapp.com/api/webhooks/291973926093848578/3JBUcZ6sStsGQ0MOdWey4oSIw11opaEPga_vw1H2MiWWimaM4vs4B44l9H7W353NkpTd" 
    local http = game:GetService("HttpService")

    local HookData = {
      ['username'] = player.Name, 
      ['content'] = message
    }
    HookData = http:JSONEncode(HookData)
    wait(0.4)
    http:PostAsync(url, HookData) 
  end
end)

Local script

local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent


local textBox = Instance.new("TextBox")
textBox.Parent = screenGui
textBox.Position = UDim2.new(0, 700, 0, 300)
textBox.Size = UDim2.new(0, 150, 0, 50)
textBox.BackgroundColor3 = BrickColor.White().Color
textBox.Text = "Type Your Message Here"


 textBox.FocusLost:connect(function(enterPressed)
  if enterPressed then
      -- So much cleaner and safer
      game.ReplicatedStorage.DiscordEvent:FireServer(textBox.Text)
  end
end)

So now your GUI is filtering compatible and much easier to work with. Everyone is happier!

2 comments

0

you forgot to change app.com to .osyr.is

0

discordapp.com is blocked in roblox

This discussion is preserved as it was. New answers, comments, and votes are closed.