[HOWTO] Send Discord messages with CFX-Server

You can send me your code in PM if you want I can try to help

Just tried this…

I put the code into my chat/chat_server.lua and i get an error

https://gyazo.com/57591c8256ee67a78c535621bf9cea3f

AddEventHandler('chatMessage', function(source, name, message)
  PerformHttpRequest('https://discordapp.com/api/webhooks/325587327856672770/ST7WRHRZILCPWua7WWtn6L3PC5Blp1yJ-4-XXXXXXXXXXXXXXXXXXXXX', function(err, text, headers) end, 'POST', json.encode({username = name, content = message}), { ['Content-Type'] = 'application/json' })
end

The XXXXXX is to hide my information

Huu yeah I think it’s missing the last parenthesis, I fixed it in the topic :slight_smile:

1 Like

Thank you :slight_smile: 20CHAR

[EDIT] Works :smiley:

https://gyazo.com/3c11b3d2974b876b4184bec21f631c5a

How would i add the player join and player left? :slight_smile:
Sorry hehe

[EDIT] Nevermind was simple, Thank you Eliakoh

Do you think its possible to do it backwards? So i can use the discord to force messages to the server?

[edit] i would also make sure in your description that only use of the server owner should see the chat log, Unless you have a system in your server that makes it so they can accept there privacy being seen by other admins etc, I hope this makes sense

Yes that should be possible using the Discord API, but you’ll have to check the doc and do that by yourself :slight_smile:

I think I see what you mean, but as the server is public too, I’m not sure it’s a big deal. I mean you’re not supposed to tell private stuff on public servers anyway

1 Like

This is nice, but i dont want it to display commands, like /ban /kick, all commands really

Works like a charm on an Fx-Server ! Would it work on a Citizen.MP Server ?

I can’t get this to work, no matter what I do. Plus, the tutorial is a bit vague as to where to put the webhook text.

I posted it in both the game chat and in the console, neither worked :confused:

Hey sorry for the late answer but the script was initially made for the Citizen version, I’m glad to hear it works on the new version too.

I am not sure what you mean but the code must be placed in the server script.

works great! thx

can you put too each 15 min how much gamers they are on the server ?

Great thank you
how to send message from Discord to chat server ??

yes, how to send msgs from discord to server

You should be able to do that by triggering an event from a client with a timer, but you’ll have to do that by yourself.

Check this thread :

and specially that answer from Havoc :

by the way your playeractivated is not working for me i had to do it this way and it worked.

AddEventHandler('playerConnecting', function()
  sendToDiscord('system', GetPlayerName(source) .. ' joined.')
end)
1 Like

which URL?
should i use

Click a cog on the channel you want to send messages to, click “Webhooks”. The URL provided there is the one you want to use.

how would i get this to work with /911

you are beautiful

1 Like

Any one Help mee player join and leave its not working