---
description: Adding DiscordKit to your project
---

# Installation

These instructions assume you already have a project in mind that you'd like to add DiscordKit to. If not, follow [creating-a-bot-using-an-xcode-project](creating-a-project/creating-a-bot-using-an-xcode-project "mention") first for step-by-step instructions for creating a new project.

## Swift Package Manager

Currently, the only supported method of adding DiscordKit to your project is through Swift Package Manager (SPM).

<details>

<summary>I've done this sort of thing before</summary>

**Package URL:**

```
https://github.com/SwiftcordApp/DiscordKit
```

**Branch:**

```
main
```

**Product:**

* [x] DiscordKitBot

</details>

<details>

<summary>Step-by-step instructions (Non-Xcode)</summary>

1. Open the `Package.swift` file in the text editor of your choice. It should look something like this:

```swift
// swift-tools-version: 5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "MyWonderfulBot",
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .executableTarget(
            name: "MyWonderfulBot",
            path: "Sources"),
    ]
)
```

2. Under the first `name` property, add the following lines:

```swift
dependencies: [
    .package(url: "https://github.com/SwiftcordApp/DiscordKit", branch: "main")
],
```

3. Under the `executableTarget` name property, add the following lines:

```swift
dependencies: [
    .product(name: "DiscordKitBot", package: "DiscordKit")
],
```

4. By now, your file should look something like this:

```swift
// swift-tools-version: 5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
    name: "MyWonderfulBot",
    dependencies: [
        .package(url: "https://github.com/SwiftcordApp/DiscordKit", branch: "main")
    ],
    targets: [
        // Targets are the basic building blocks of a package, defining a module or a test suite.
        // Targets can depend on other targets in this package and products from dependencies.
        .executableTarget(
            name: "MyWonderfulBot",
            dependencies: [
                .product(name: "DiscordKitBot", package: "DiscordKit")
            ],
            path: "Sources"),
    ]
)
```

5. Save the file, then in a terminal run `swift package resolve`. If the command finished with no errors, then DiscordKit was installed correctly!

</details>

<details>

<summary>Step-by-step instructions (Xcode)</summary>

1. With the project that you'd like to add DiscordKit to open in Xcode, click on **File** > **Add Packages...** in the menu bar
2. In the dialog that appears, paste **`https://github.com/SwiftcordApp/DiscordKit`** in the text field at the **top right corner**
3.  Give Xcode a moment to look up the package, and set the **Dependency Rule** to the `main` branch as shown in the image below

    <figure><img src="https://1903821505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWJuHiYLW9jKqPb7h8D7t%2Fuploads%2FBSWGhEKol4wVKb5BWlMn%2FScreenshot%202022-12-14%20at%201.08.07%20PM.png?alt=media&#x26;token=e9d050b5-c462-4cb9-802a-d0e75997c9e6" alt="Xcode Add Package dialog adding DiscordKit dependancy"><figcaption><p>Adding DiscordKit package dependancy</p></figcaption></figure>
4.  Hit the **Add Package** button ensure the **DiscordKitBot** package product is checked. Then, press the **Add Package** button once again.

    <figure><img src="https://1903821505-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FWJuHiYLW9jKqPb7h8D7t%2Fuploads%2F6OkeeNiJ0ySPUIb64gTN%2FScreenshot%202022-12-14%20at%201.09.47%20PM.png?alt=media&#x26;token=fe37c509-9bd6-41d8-afc6-0bf0843a8455" alt=""><figcaption></figcaption></figure>

If you've followed these steps successfully, you've just added DiscordKit for bots to your project!

</details>

{% embed url="https://github.com/SwiftcordApp/DiscordKitGettingStarted/tree/installation" %}
Here's how your project should look after this step!
{% endembed %}
