# Getting off the Ground

## Main Entry-point

If you've followed [Creating a Project](/discordkit-guide/getting-started/creating-a-project.md) and [Installation](/discordkit-guide/getting-started/installation.md), your project should contain a `main.swift` file with some content. It should look something this:

<figure><img src="/files/R6JuGHkGQ5xLSPUnzB0Q" alt=""><figcaption><p>A fresh Xcode project, full of possibilities</p></figcaption></figure>

As you can see, it has some example code. We don't want any of that - delete everything and replace it with the code below:

<pre class="language-swift" data-line-numbers><code class="lang-swift">import Foundation // Import Foundation. If you don't know what this is, think of it like stdlib
import DiscordKitBot // Import the DiscordKit module for all the wonders contained within

/// The main entrypoint of our Discord bot
@main
public struct Bot {
    static let bot = Client(<a data-footnote-ref href="#user-content-fn-1">intents: .unprivileged</a>)

    public static func main() {
        // This is your main function, which will be ran when your app starts
        print("Hello world!")
    }
}
</code></pre>

At this point, you might be faced with a bunch of cryptic build errors - a [known Swift compiler bug](https://github.com/apple/swift/issues/55127). I was too, and the workaround was to rename the `main.swift` file to some other name - in my case I chose `Bot.swift`, but you can choose anything that suits you. From this point on in the guide, `Bot.swift` will refer to this file and `main.swift` will no longer be used.

Now let's try and run the thing. If you're using Xcode, press the "Play" button in the top left. if you're using VSCode, press the `F5` key. Otherwise, run the command `swift run` in your terminal. Once it finishes compiling,&#x20;

{% hint style="info" %}
Note that the first time that you compile you bot, compilation will take significantly longer than subsequent builds, especially on Linux. This is because swift is building your dependency cache. Please be patient as it does so.
{% endhint %}

We've created a simple main entry-point for your app, which is more scalable and encapsulated than the original code. Next, let's securely add our bot's token to the environment.

## Bot Token

There are 2 ways to provide your Bot token.

<details>

<summary>Providing a bot token with a file</summary>

You can store your token in a separate file, and then load the contents of that file as a string. Here is a code example of this method, which loads the token from a file in the current working directory called `token.txt`:

```swift
static let bot = Client(intents: .unprivileged)
// Loads the contents of the file "token.txt" as a string
// (will crash if the file is not found!)
static let token = try! String(contentsOfFile: "token.txt")
public static func main() {
    bot.login(token: token) // Log in with the loaded token
}
```

Make sure to add the file containing your token to your `.gitignore` file, so that you don't accidentally upload your token to the internet!

</details>

<details>

<summary>Providing a bot token with an environment variable</summary>

You can provide your bot token in the environment variable `DISCORD_TOKEN`. Then simply call `bot.login()` to connect your bot to Discord.&#x20;

</details>

{% embed url="<https://github.com/SwiftcordApp/DiscordKitGettingStarted/tree/getting-off-the-ground>" %}
Confused? No worries! Check out this branch for an example about how your project should look at this stage.
{% endembed %}

[^1]: These intents do not require any special actions in the Discord Developer Portal. You might need to enable other intents if you require more privileged information, such as message content.


---

# 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://swiftcord.gitbook.io/discordkit-guide/build-a-bot/getting-off-the-ground.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.
