Hello,
I just need help trying to add join/disconnect messages to my discord chat (I’ve already added regular chat messages).
Here is the handler I already have:
AddEventHandler('chatMessage', function(source, name, message)
PerformHttpRequest('discordwebhooklink', function(err, text, headers) end, 'POST', json.encode({username = name, content = message}), { ['Content-Type'] = 'application/json' })
end)
I’d like to add the extra join/disconnect messages in an event handler similar to the one listed above.
Thanks!
This should help you a bit
DavidR
3
AddEventHandler('playerDropped', function(reason)
name = GetPlayerName(source)
PerformHttpRequest('discordwebhooklinkd ', function(err, text, headers) end, 'POST', json.encode({username = "Leaves", content = "User "..name.." Left the server for the Reason:"..reason.."."}), { ['Content-Type'] = 'application/json' })
end)
AddEventHandler('playerConnecting', function(reason)
name = GetPlayerName(source)
PerformHttpRequest('discordwebhooklinkd ', function(err, text, headers) end, 'POST', json.encode({username = "Leaves", content = "User "..name.." Left the server for the Reason:"..reason.."."}), { ['Content-Type'] = 'application/json' })
end)
should work my dude!
Thanks buddy!
Been lookin for this for awhile.
@DavidR I tried to add another EventHandler from essentialmode and got a scheduling error.
AddEventHandler('es:commandRan', function(source, command_args, user)
name = GetPlayerName(source)
PerformHttpRequest('webhooklink', function(err, text, headers) end, 'POST', json.encode({username = "Command Log", content = "** "..name.." has ran the command "..command_args.."!**"}), { ['Content-Type'] = 'application/json' })
end)
Any idea what may be wrong? I want the discord webhook to say User has ran the command (commandhere)!
DavidR
5
What is the command meant to do so we can understand better?
PerformHttpRequest('webhooklink', function(err, text, headers) end, 'POST', json.encode({username = "Command Log", content = "** "..name.." has ran the command "..command_args.."!**"}), { ['Content-Type'] = 'application/json' })
end)
Im pretty sure all u do is add this after the command? But change it to what you need/want for the code to actually work.
1 Like