# 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](/scripting/bedwars-scripting/objects/player.md)

The player that sent the message

#### message: string

The message sent by the player


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.easy.gg/scripting/bedwars-scripting/events/playerchatted.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
