DiscordKit Guide
GitHub Repository
  • 👋Welcome
  • 🚀Getting Started
    • Creating a Project
      • Creating a bot using a SPM project (Recommended)
      • Creating a bot using an Xcode Project
    • Installation
    • Example Project
  • ðŸĪ–Creating a Bot
    • Getting off the Ground
    • Logging In
    • Registering Commands
    • Responding to Commands
    • Adding Command Options
    • Deploying on Linux
  • ðŸŠĶLegacy
    • Message Commands
  • âœĻEnhancements
    • Logging
  • ðŸ“ĶNitty-gritty
    • What's in the box?
    • Gateway
    • Event Dispatching
Powered by GitBook
On this page
  1. Getting Started

Installation

Adding DiscordKit to your project

PreviousCreating a bot using an Xcode ProjectNextExample Project

Last updated 1 year ago

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 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).

I've done this sort of thing before

Package URL:

https://github.com/SwiftcordApp/DiscordKit

Branch:

main

Product:

Step-by-step instructions (Non-Xcode)
  1. Open the Package.swift file in the text editor of your choice. It should look something like this:

// 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"),
    ]
)
  1. Under the first name property, add the following lines:

dependencies: [
    .package(url: "https://github.com/SwiftcordApp/DiscordKit", branch: "main")
],
  1. Under the executableTarget name property, add the following lines:

dependencies: [
    .product(name: "DiscordKitBot", package: "DiscordKit")
],
  1. By now, your file should look something like this:

// 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"),
    ]
)
  1. Save the file, then in a terminal run swift package resolve. If the command finished with no errors, then DiscordKit was installed correctly!

Step-by-step instructions (Xcode)
  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

  4. Hit the Add Package button ensure the DiscordKitBot package product is checked. Then, press the Add Package button once again.

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

🚀
Adding DiscordKit package dependancy
Xcode Add Package dialog adding DiscordKit dependancy
GitHub - SwiftcordApp/DiscordKitGettingStarted at installationGitHub
Here's how your project should look after this step!
Logo