# Tommy's Discord API

<figure><img src="/files/vBVLsZygBJtM2sJyDPSm" alt=""><figcaption></figcaption></figure>

[FiveM Post](https://forum.cfx.re/t/tommys-discord-api-tool-for-devs/4806569) | [Store Page](https://tommy141x.tebex.io/)

#### Escrow Encrypted: Yes

#### Requirements: None

This tool easily allows for discord integration in scripts.

### Why this API?

There are many resources that already serve a similar purpose, however, the methods in which these resources acquire discord information is not reliable. **Discord Data Saver** stores players' discord IDs and caches role information. No longer will your players have issues with discord permissions.

### How do I use it?

1. Configure the Guild ID & Bot Token in the `config.lua` file.
2. Add the following to your resources `fxmanifest.lua`:

```lua
dependency 'ddSaver'
```

#### Client Exports

```lua
luaCopy codeexports.ddSaver:getRoles() -- Returns a table of role IDs
exports.ddSaver:getId() -- Returns the player's discord ID
exports.ddSaver:refreshData() -- Refreshes the player's discord data
exports.ddSaver:hasRole("roleid") -- Returns true or false
```

#### Server Exports

```lua
luaCopy codeexports.ddSaver:getRoles(source) -- Returns a table of role IDs
exports.ddSaver:getId(source) -- Returns the player's discord ID
exports.ddSaver:refreshData(source) -- Refreshes the player's discord data
exports.ddSaver:hasRole(source, "roleid") -- Returns true or false
```

### Examples

#### `client.lua`

```lua
luaCopy codelocal leoRole = "909620367654543381"

if exports.ddSaver:hasRole(leoRole) then
  print("omg you have the role")
end

RegisterCommand('permcheck', function(source)
  exports.ddSaver:refreshData()
  TriggerEvent("chatMessage", "Discord Permissions", {20, 20, 20}, "Permissions Updated.")
end, false)
```

#### `server.lua`

```lua
luaCopy codeRegisterCommand('printRoles', function(source)
  local roles = exports.ddSaver:getRoles(source)
  if roles then
    for role in pairs(roles) do
      print("Role Found: " .. roles[role])
    end
  end
end, false)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tommys-scripts.gitbook.io/fivem/free-scripts/tommys-discord-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
