---
description: commands --help
---

# Adding Command Options

You now have a bot that uses slash commands, what's next? Command options, of course! They make your commands dynamic and are a crucial part of most commands. And of course, they're easy-as-pie to work with, thanks to the `resultBuilder` syntax used by DiscordKit.&#x20;

{% hint style="info" %}
**What are `resultBuilder`s?**

If you've used SwiftUI or even DiscordKit, you've already used them! They allow the special syntax you can use to create commands! It's special syntax that allows building multiple "blocks" into a "stack" (i.e. array), such as creating SwiftUI views or registering your bot's commands! In this page, we'll be further using this syntax to register, you guessed it, command options.
{% endhint %}

Let's try adding options to the **/hello** command we previously added. A `name` option would be really handy, so we could give the user personalised hello messages for increased _human-ness_.

To do so, we can add option children blocks to the **/hello** command we defined earlier, similar to how you'd add children to a SwiftUI view:

<pre class="language-swift"><code class="lang-swift">NewAppCommand("hello", description: "Get a nice hello message") {
    StringOption("name", description: "Your beautiful name")
} <a data-footnote-ref href="#user-content-fn-1">handler:</a> { interaction in
    print("Received hello interaction!")
    // Reply with a random hello message
    try? await interaction.reply(HELLO_MESSAGES.randomElement()!)
}
</code></pre>

Then, we'd need to handle the value of the name option, if one is given. As we did not specify that our option is required, it's optional by default. The `interaction` struct passed to your handler contains the `optionValue(of:)` method that allows easy retrieval of option values. Let's modify the handler to send back a personalised hello message if a name was specified, otherwise just return a random hello message as usual.

```swift
    ...
} handler: { interaction in
    print("Received hello interaction!")
    if let name: String = interaction.optionValue(of: "name") {
        try? await interaction.reply("Hello \(name), hope you're having a wonderful day!")
    } else {
        // Reply with a random hello message
        try? await interaction.reply(HELLO_MESSAGES.randomElement()!)
    }
}
```

Here, we're using an optional binding to conditionally unwrap and run a block of code if the **name** option isn't `nil` (which means it was specified by the user). The `else` clause will be run if the value of the option is `nil`.&#x20;

Give the command a go - with just a few lines, you've added and handled your bot's first command option! How cool is that?

<figure><img src="https://1903821505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWJuHiYLW9jKqPb7h8D7t%2Fuploads%2FWXBlFZiWNfl0FTXtsQIP%2FScreenshot%202022-12-20%20at%2011.14.05%20AM.png?alt=media&#x26;token=6c21bf40-2e17-4ef7-b1d0-54405991f86c" alt=""><figcaption><p>bbbbb &#x3C;insert realistic surname></p></figcaption></figure>

{% embed url="https://github.com/SwiftcordApp/DiscordKitGettingStarted/tree/adding-command-options" %}
That didn't work? Check out the code in this branch for a helping hand!
{% endembed %}

[^1]: Take note of the addition of this label: It's required as there are now 2 clauses, so a label for the latter option is required.
