> For the complete documentation index, see [llms.txt](https://ghom.gitbook.io/bot.ts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ghom.gitbook.io/bot.ts/native-commands/eval.md).

# Eval

## Description

This command is surely the most useful of all, after the help command of course. It is used to execute JavaScript critical code directly on the server where the bot is located. This can be used in particular to test features or to do debugging.

The package used by this command to resolve the code is on npm as [discord-eval.ts](https://www.npmjs.com/package/discord-eval.ts), which itself uses [ghom-eval](https://www.npmjs.com/package/ghom-eval). These two packages are created by the creator of this framework.

## Command pattern

In the Discord server where you invited the bot, use the following command pattern in a channel accessible by the bot.

```bash
.eval <code> [--muted: <boolean>]
```

For example:

```bash
.eval
return 42 + "0"
```

## Automatic return

If you type your entire command on one line, you can ignore the keyword `return`. It will be added automatically.

```bash
.eval 42 + "0"
```

## Code blocks

You also have the possibility to encode your code between markdown tags in order to have the indentation.

````haskell
.eval ```js
return 42 + "0"
```
````

## Async / Await

If your code contains `async/await`, it works at top level like on Deno!

```javascript
.eval await fetch("https://api.mathjs.org/v4/?expr=42+0")
```

## Arguments

{% hint style="warning" %}
Check the [Command](/bot.ts/usage/create-a-command.md)/[Arguments](/bot.ts/usage/create-a-command.md#arguments) section if you have a problem.
{% endhint %}

### --muted

If you want to run your code in silence, use the `--muted` flag (or just `-m`).

```bash
.eval --muted
return 42 + "0"
```

## Annexes

* [Command file](https://github.com/bot-ts/framework/blob/master/src/commands/eval.native.ts)
* [discord-eval.ts](https://www.npmjs.com/package/discord-eval.ts)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://ghom.gitbook.io/bot.ts/native-commands/eval.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.
