Registers a slash command. Players and the server console can run plugin commands.
| Name | Type | Description |
|---|---|---|
name | string | Command name, without the slash. |
options | table or function | Either the handler (short form) or a table with description, usage, aliases, op and permission. |
handler | function | Called as function(sender, args, label). Return false to print usage; true or no return value counts as handled. args contains strings and label is the lowercased command or alias entered. |
command('greet', {
description = 'Greet a player',
usage = '/greet <name>',
aliases = {'hi'},
op = true
}, function(sender, args)
if not args[1] then return false end
local target = server.player(args[1])
if not target then
sender:send('Player is offline')
return true
end
target:send('Hi from ' .. sender.name .. '!')
return true
end)
/greet "John Smith" gives args = { '"John', 'Smith"' }. Console senders are always allowed through command permission checks. For player-only methods, check sender.isPlayer first.