Docs/Library/Modules/addCommand

addCommand

Library
Updated 2 months ago · v1.3.7
i

Server Module - This can only be used on the server

lib.addCommand

Register a chat command with automatic parameter parsing, type validation, and ACE permission restrictions.

lua
lib.addCommand('givemoney', {
    help = 'Give money to a player',
    restricted = 'group.admin',
    params = {
        { name = 'target', type = 'playerId', help = 'Target player' },
        { name = 'amount', type = 'number',   help = 'Amount to give' },
        { name = 'reason', type = 'longString', help = 'Reason', optional = true },
    },
}, function(source, args, raw)
    lib.player.addMoney(args.target, 'cash', args.amount, args.reason or 'admin')
end)

Signature

lua
lib.addCommand(commandName, properties, cb)
ParameterTypeRequiredDescription
commandNamestring | string[]yesCommand name(s) to register
propertiestable | falseyesCommand properties, or false for no restrictions/params
cbfunctionyesHandler function(source, args, raw)

Properties

FieldTypeDescription
helpstringDescription shown in chat suggestions
restrictedstring | falseACE permission required (e.g. "group.admin")
paramstable[]Parameter definitions

Parameter Types

TypeDescription
numberParsed as a number
playerIdValidated server ID of an online player
stringSingle word string
longStringRest of the input as one string (must be last param)

Multiple Aliases

Pass a table to register the same handler under multiple command names:

lua
lib.addCommand({'tp', 'teleport'}, { ... }, function(source, args) end)
Was this page helpful?
This page was last updated on 12 March 2026
DIRKSCRIPTS
All you need for your FiveM server.10% off your first order

Unsubscribe any time.

Copyright © 2026 DirkScripts. Not affiliated with or endorsed by Rockstar North or Take-Two Interactive.