Calling Kord constructor throws IOException
I have just setup a new Kotlin project in Intellij
I implemented the code as shown in the "Making a simple ping-pong bot" section of the github wiki, adding my own token
this throws the following exception:
https://pastebin.com/n9FESr6k
my pom.xml:
https://pastebin.com/F5EEAXQ6
Version: 0.15.0
JDK: 24
I feel like something with my setup is probably wrong but I'm absolutely stumped as to what it could be at this point
Pastebin
SLF4J(W): No SLF4J providers were found.SLF4J(W): Defaulting to no-...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
56 Replies
looking into it
does maven not support api-scoped dependencies?
nah it must do
you have kord core, so you don't need to add common, rest or gateway
unless maven doesn't add them to your compile classpath for some reason
the root cause of the exception is that the
kotlinx.io
on your classpath is the wrong version, or missing entirely
you're going to have a very difficult time finding anyone with any deep experience with maven in the kotlin community thoughah, I originally only had core but wanted to make sure it's not that I'm missing something so I tried adding the others
if you go down the traceback you can see the root cause
Caused by: java.lang.ClassNotFoundException: kotlinx.io.unsafe.UnsafeBufferOperations
so my best bet is probably to make a gradle project instead?
I would generally recommend using Gradle yeah
are you familiar?
kinda, I've used it here and there
well before we get to that
I mostly wanted to go with maven because the service I wrote is already in maven
how do you plan to distribute your bot?
or well, the correct term I should use there is package
single jar? distribution zip? docker container?
it's been too long since I did anything with discord bots 😅 whatever runs on a raspberry will be fine
what model?
i think 3b
a 3b or 3b+?
I'm not sure
actually it doesn't seem to matter
they both only have about a gig of ram
you're probably not going to manage to run a jvm bot on that
the good news is that kord isn't jvm-only
tbh, I'm still quite far from that, first I wanna get the bot running locally
alright, fair
well, the root of your current issue is a missing/incorrect kotlinx.io
GitHub
GitHub - Kotlin/kotlinx-io: Kotlin multiplatform I/O library
Kotlin multiplatform I/O library. Contribute to Kotlin/kotlinx-io development by creating an account on GitHub.
however
you should think about how you want to package it
your pom doesn't show any signs of having thought of that, so it might be the case that you're not done configuring your project
if you're trying to just run the bot's jar then this configuration as written likely won't work, because the jar won't contain any of the dependencies
you're very much right, what would you recommend I use to package it to a jar?
in gradle I'd generally recommend the distribution plugin
with maven, I'm not sure
the distribution plugin packages your project along with its dependencies in a .zip or .tar archive, including some start scripts
you'd just unpack the archive and run the script
hmm, I think I might just have to convert the service I have to gradle and make a new gradle project for the bot
you don't need to convert any other projects
unless they're in the same build unit, I guess
sorry, it's just that gradle is the standard build tool for kotlin, so that's what most people will know
ah, no worries, we're just using maven with kotlin primarily at work, so I thought I might just go with that haha
didn't know we were actually the odd ones out
I wanted to add the service as a dependency to the bot, so I think I'll have to make it a gradle project
if it's published in a maven repo, there's no need
it's all local for now
You can use
mavenLocal()
if you installed it to your local maven repo
I do recommend trying gradle before converting other projectsalright, I added a new module with gradle now and replaced the main with the code from above and it works without problem now
okay, interesting
so then maybe it is the case that maven isn't pulling in all the dependencies
seems like it
okay, so
before you get stuck into this
I implore you to be careful about how you write this code given you need to run this on 1 gig of ram and a 1.2GHz/1.4GHz CPU
there are additional frameworks that build on top of Kord, I maintain one of them (KordEx)
I very much do not recommend using one
make this as lean as you possibly can
current plan is two slash commands for private use on a single discord server
you think a raspberry could handle that?
it should
however
do you know javascript?
also, eureka!
i simply added the dependency for kotlinx to the pom.xml, now the maven project works too
i've used it a bit, yeah
okay so yeah that is what it was lmao
do you actually need the discord gateway?
or could you get away with a REST-only bot?
that I had in the pom.xml?
no, not exactly
okay, so Discord bots ("apps") can take two forms
the one you're familiar with, a traditional bot, is a process that connects to Discord's gateway, which is a websocket, and processes events and data in realtime as it's given them
however, if you're just doing slash commands, and you don't need the usual set of events, you probably don't actually need that
oh, so there's like a lightweight version for that?
the other form is a REST-only bot, where discord will essentially send data to a webhook when one of your commands are run
you can technically do that with Kord and ktor, but
since you seem to be limited on capacity here, you might be able to get away with using a cloudflare worker on the free tier
feel free to continue on with kord if you like, it will probably work fine, but that's also an option if you feel like looking into it
GitHub
GitHub - discord/cloudflare-sample-app: Example discord bot using C...
Example discord bot using Cloudflare Workers. Contribute to discord/cloudflare-sample-app development by creating an account on GitHub.
oh cool, that sounds like it might be a good idea
i'll check out the sample project
it'll likely be considerably more reliable than running on a pi that old
that's my thinking
completely fair, I'm not even sure where it is haha
I have used pis in production ftr
those things are basically disposable
they die
so I do recommend something like this over that
it does seem like the easier version
considering I wouldn't need to go unpack a bunch of boxes in the hope of finding the pi 😅
haha
well then, best of luck with it
I will say I haven't done it myself, but I do know people that have
thanks a lot for the quick help and great suggestions!
appreciate it a lot :tabbylove:
you're welcome
even though I am personally invested in kord's ecosystem
it just
isn't really the right option here imo
that's how it goes sometimes
definitely a type of bot I haven't made so far, they were all "traditional" bots as you put it
REST-only bots are a much newer concept
so yeah a lot of people don't know about them
yeah, haven't made bots in a few years, so I wasn't really aware
ah yeah, you might've even stopped before they came in
they are very convenient once you get used to the workflow, or so I'm told
there are likely better libraries as well since discord made that example
probably, I've been at it for almost 8 hours at this point so I think I'll go and continue this tomorrow 😅
haha, good call, rest is important
well then, thanks again, have a great day/night/wherever you are 😄
you're welcome, good luck with it :>