Discord to FiveM & FiveM to Discord

Hi! So I was wondering how I could communicate FiveM with my Discord bot and vice versa. I want to do this for Discord Account linking, bans, and other stuff.

If you have any ideas or any resources, please let me know of them!

My current idea is some sort of HTTP requests.

Thanks!

Bump. Need help still.

1 Like

I used PerformHttpRequest to interact with webhooks and the REST API in order to connect a Discord channel to the in-game chat on my servers: GitHub - kibook/poodlechat: Chat resource for Poodle's Palace FiveM/RedM server.

There are Discord libraries for most programming languages, including Lua, which should be easier to use than dealing with raw HTTP requests and responses, but I’m not sure whether there would be any challenges using them within a FiveM resource.

2 Likes

I don’t really want to use webhook’s because I have to find users in the server.

I use a webhook for sending messages from in-game to Discord, specifically because a webhook has the ability to use a different name per message. That way, I can use the name of the player in-game for the name on the message on Discord. From what I understand, Bots are more like actual users, in that if you change the name of a bot, the change will affect all of the previous messages sent by that bot as well, which wouldn’t work for me.

For sending messages from Discord to the in-game chat, I use the REST API to interact with a bot. For example, I get a list of messages sent to a channel that the bot is in with https://discord.com/developers/docs/resources/channel#get-channel-messages, and then send those messages as chat messages in-game.

As another example, you mention finding users in the server. If you mean the Discord server (referred to as a “guild” in the API), then I think you can use this method: https://discord.com/developers/docs/resources/guild#list-guild-members. Sending a request to https://discord.com/api/guilds/{guild.id}/members, where {guild.id} is the ID of the Discord server, should return a list of users for that server.

So, can I for example make a POST request to my bot via a website hook, and trigger a function with that? Of course include security.

Not via a Discord webhook. A Discord webhook can only receive information from outside Discord and post it in a Discord channel. You can with the Discord REST API, though.

A POST request to the URL given for https://discord.com/developers/docs/resources/channel#create-message, as another example, allows you to post a message in a channel with your bot.

Checkout my way of doing Discord To Fivem
i hope it will be helpful
Discord Command Bot

1 Like