Building a Discord Bot

Hello all!

I am trying to make a Discord bot using the Sword API on Discord. There aren't really any tutorials for this sort of thing so I've been following along with a channel called The Source Code on YouTube as best I can. The only problem here is that the author of this video uses node.js.

As Swift is my first language, I would like to build a few things with it before starting other languages.

I'm currently building a command handler and am fairly comfortable with debugging, classes and subclasses. My problem now is that I'm trying to tell my bot to look at a particular directory for a particular file extension and I'm stuck on how to do this without hardcoding my file path.

One way I've thought to do this is by jamming all my .json and .swift (excluding main.swift) files into my build directory and using Bundle.main.url to find/filter files. The only issue with this is the potential of losing all that work if I need to run Cmd + Shift + K to clean my build directory.

I've found a potential solution in the video below however it makes use of node.js which I am not comfortable with. Would someone be able to break down the two sections of the video linked below and how I can accomplish this task in Swift?

I'm using Xcode 10 on a 2011 MBP with Swift 4.2

Thank you,

  • L33t

Section the first
Section the second

Edit: Here is a WIP gist for clarity


Thank you

It's not necessarily specifically Sword related, I just happen to be using the API

At the time of this comment, neither Sword nor Shield natively supports multiple command prefix branches(?) so I'm trying to construct my own handler with that API

Right now I'm at the stage of being able to have the bot look for a file to run a function or closure or whatever instead of writing them all out in my main.swift file

I feel like this is doable in Swift as a basic thing without the API being necessary

If I could possibly even use a relative path instead of an absolute one that might work better

It's just that hardcoding the path has personal info in it that I don't want to reveal

CC @MrLotU who I think was also working on a Discord bot?

1 Like

I think this question was already picked up in the Sword channel in the Discord API server. If not, that'd be the place to ask it.

1 Like
Terms of Service

Privacy Policy

Cookie Policy