# PlayerChatted

Example usage:

<pre class="language-lua"><code class="lang-lua"><strong>-- Add "/rain {item}" command that rains a resource on all players
</strong>Events.PlayerChatted(function(event)
    -- Split out command from args
    local commandArgs = string.split(event.message, " ")
    
    local command = string.lower(commandArgs[1])
    
    -- Check that command is "/rain"
    if string.lower(command) ~= "/rain" then
        return
    end
    
    -- Verify message at least has 2 arguments (command &#x26; item type)
    if #commandArgs &#x3C; 2 then
        MessageService.sendInfo(event.player, 'Format: /rain &#x3C;Item Type>')
        return
    end
    local itemType = string.lower(commandArgs[2])
    
    -- Check that item exists
    if not ItemType[itemType] then
        MessageService.sendInfo(event.player, 'No item exists named ' .. itemType)
        return
    end
    
    local numDrops = 25
    task.spawn(function()
        for i=1,numDrops,1 do
            for i,player in ipairs(PlayerService.getPlayers()) do
                local entity = player:getEntity()
                if not entity then
                    continue
                end
                
                local pos = entity:getPosition()
                pos = pos + Vector3.new(math.random(-5, 5), 8, math.random(-5, 5))
                ItemService.dropItem(itemType, pos)
            end
            task.wait(0.2)
        end
    end)
end)
</code></pre>

### Parameters

#### player: [Player](https://docs.easy.gg/scripting/bedwars-scripting/objects/player)

The player that sent the message

#### message: string

The message sent by the player
