Home / Commands

command()

command(name, options, handler) command(name, handler)

Registers a slash command. Players and the server console can run plugin commands.

Parameters

NameTypeDescription
namestringCommand name, without the slash.
optionstable or functionEither the handler (short form) or a table with description, usage, aliases, op and permission.
handlerfunctionCalled 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.

Example

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)

Notes

Arguments are split on spaces. Quotes are not grouped, so /greet "John Smith" gives args = { '"John', 'Smith"' }. Console senders are always allowed through command permission checks. For player-only methods, check sender.isPlayer first.