# チャットコマンドを引数付きで実行する（player.runChatCommandWithArguments）

> コード内でチャットコマンドを引数付きで実行します。

- カテゴリ：プレイヤー（player）
- ブロック：チャットコマンド "jump" を 引数 "5" で 実行
- URL：https://makecode.minecraft-okinawa.com/reference/player/run-chat-command-with-args/
- Pythonでの名前：player.run_chat_command_with_arguments
- 公式データ取得日：2026-11-13
- 動作確認：確認待ち

## JavaScript

```javascript
player.runChatCommandWithArguments("jump", "5")
```

## Python

```python
player.run_chat_command_with_arguments("jump", "5")
```

## 引数

| 名前 | 値 | 意味 |
|---|---|---|
| command | 文字列 | 実行するチャットコマンド。たとえば：「jump」 |
| arg | 文字列 | チャット コマンドで利用したいすべての引数を含む文字列 |

## 使用例

### Let's say you have a chat command in your project that makes your agent build a row of blocks of variable length:

```javascript
player.onChat("row", function (length) {
    for (let i = 0; i < length; i++) {
        agent.move(FORWARD, 1);
        agent.place(BACK);
    }
})
```

```python
def on_on_chat(length):
    for i in range(length):
        agent.move(FORWARD, 1)
        agent.place(BACK)
player.on_chat("row", on_on_chat)
```

### You can reuse this chat command in other parts of your code to build a square, for example:

```javascript
player.onChat("square", function () {
    agent.teleportToPlayer()
    agent.move(FORWARD, 1)
    for (let i = 0; i < 4; i++) {
        player.runChatCommandWithArguments("row", "5")
        loops.pause(5000)
        agent.turn(TurnDirection.Left);
        agent.move(FORWARD, 1)
        agent.move(LEFT, 1)
    }
});
```

```python
def on_on_chat():
    agent.teleport_to_player()
    agent.move(FORWARD, 1)
    for i in range(4):
        player.run_chat_command_with_arguments("row", "5")
        loops.pause(5000)
        agent.turn(TurnDirection.LEFT)
        agent.move(FORWARD, 1)
        agent.move(LEFT, 1)
player.on_chat("square", on_on_chat)
```

## 出典

- [MakeCode for Minecraft 公式リファレンス（player.runChatCommandWithArguments）](https://minecraft.makecode.com/reference/player/run-chat-command-with-args)

執筆：鈴木孝昌（現役プロジェクトマネージャー／マイクラカップ指導者）／運営：沖縄マイクラ部 プログラミングスクール「クロスウェーブ」（https://minecraft-okinawa.com/）