π¨Discord.lua
The discord.lua file manages logging and integration with Discord for the Collectibles Pickup Script. It allows you to track player activity, such as when collectables are picked up, and send detailed
Configuration Options
π§ sendToDiscord
sendToDiscord
This function handles sending logs when specific actions occur in the script. It can be extended to support additional events as needed.
Parameters:
source
: The playerβs server ID.type
: The type of event to log (e.g.,'collected'
).args
: A table containing event-specific details.
Supported Event Types
1. collected
collected
Logs details when a player collects a collectable item.
Arguments in args
:
Field
Type
Description
identifier
String
The player's license or unique identifier.
coords
Table
The coordinates where the collectable was picked up.
totalPickups
Integer
The total number of collectables collected by the player.
timestamp
String
The timestamp of when the collectable was picked up.
Log Format Example:
When a player collects a collectable, the log will appear as:
π€ **Player:** JohnDoe (ID: 1)
π **License:** license:abcdef1234567890
π **Coords:** {"x":123.45,"y":678.90,"z":21.0}
π― **Total collectables:** 5
π **TimeStamp:** 2025-01-01 12:00:00
Default Behavior
The sendToDiscord
function is preconfigured to use QBCore's logging system (qb-log
). By default, it logs 'collected'
events to a specific Discord channel.
Default Log Implementation:
TriggerEvent('qb-log:server:CreateLog',
'collectables',
'π¦ **Collectable Collected**',
'blue',
logMessage
)
Extending the Configuration
The sendToDiscord
function is designed to be easily extended for additional events or frameworks. Hereβs an example of how you can add a new event type:
Example: Adding a rewardClaimed
Event
rewardClaimed
EventModify the sendToDiscord
function as follows:
if type == 'rewardClaimed' then
local logMessage = string.format(
"π€ **Player:** %s (ID: %d)\n" ..
"π **Reward Claimed:** %s\n" ..
"π― **Total Rewards:** %d\n" ..
"π **TimeStamp:** %s",
GetPlayerName(source), source, args.rewardName, args.totalRewards, args.timestamp
)
TriggerEvent('qb-log:server:CreateLog', 'rewards', 'π **Reward Claimed**', 'green', logMessage)
end
At a Glance
Option
Description
sendToDiscord
Sends logs to Discord or a logging system based on the event type (collected
, etc.).
collected
Logs details about collected items, including player info, coordinates, and timestamps.
Tips and Recommendations
1. Adapting to Your Logging System
If your server does not use QBCore's logging, replace the qb-log
call with your preferred Discord logging system, such as Discord Webhooks or another logging resource.
Example: Using Discord Webhooks
PerformHttpRequest('https://discord.com/api/webhooks/your_webhook_url', function(err, text, headers) end, 'POST', json.encode({
username = 'Collectables Logger',
embeds = {
{
title = "π¦ Collectable Collected",
description = logMessage,
color = 3447003 -- Blue color
}
}
}), {['Content-Type'] = 'application/json'})
2. Add More Event Types
Expand the sendToDiscord
function to log additional events, such as reward claims, player joins, or admin actions.
Example Default Configuration
Hereβs the default configuration provided in the script:
DiscordConfig = {
sendToDiscord = function(source, type, args)
if type == 'collected' then
local logMessage = string.format(
"π€ **Player:** %s (ID: %d)\n" ..
"π **License:** %s\n" ..
"π **Coords:** %s\n" ..
"π― **Total collectables:** %d\n" ..
"π **TimeStamp:** %s",
GetPlayerName(source), source, args.identifier, json.encode(args.coords), args.totalPickups,
args.timestamp
)
TriggerEvent('qb-log:server:CreateLog', 'collectables', 'π¦ **Collectable Collected**', 'blue', logMessage)
end
end,
}
Last updated