# Running Commands

##### Preface

Sometimes, you might want to run a command (such as `/tell @a Hi!`), in your code.

Most always, there is better method, but sometimes, you just don't want to learn more complicated topics, and just run a command.

##### Basic Usage

The most basic usage would be to call `runCommand()` from a `server` class.

```JavaScript
Utils.server.runCommand(`tell @a Hi!`)
```

<p class="callout warning">If this command returns a message (usually an error) that is normally placed chat, it will be logged. This is not desired outside of debugging situations.</p>

 So instead you can use the following to not log these messages.

```JavaScript
Utils.server.runCommandSilent(`tell @a Hi!`)
```

<p class="callout warning">If the server is not loaded at the time this is ran, then the code will not work.</p>

<p class="callout warning">Although you can use `player.runCommandSilent()`, it is not recommend as the command runs with the players permission level.</p>

##### Using the execute command

<p class="callout warning">Commands are ran in the default dimension (the overworld usually) at 0, 0, 0</p>

To get around this, you can use the execute command:

```JavaScript
//This example makes a bedrock box around creepers when they spawn
onEvent('entity.spawned', event => {
	if (event.entity.type != "minecraft:creeper") return // the following code only runs when creepers are spawned
	event.server.runCommandSilent(`execute in ${event.entity.level.dimension} positioned ${event.entity.x} ${event.entity.y} ${event.entity.z} run fill ~-1 ~-1 ~-1 ~1 ~2 ~1 bedrock hollow`)
})
```