Slash Command not showing
Hey! so, a previous dev decided to be a dick & let a community hanging. I've never used Sapphire before but making my way along, I just created a new slash command & I'm yet to see them. Why is this? I know for discord.js I would have to provide them all at once, what do I do for sapphire?
226 Replies
@Helpers hate to ping, but i've been waiting for an answer; currently trying to get this implemented asap!!
what do the logs say?
also you dont need id hints
most of the time you also need to restart your discord client for them to show if they were deployed correctly
doesn't say anything, they don't show the command in general
oh okay i'll try that
sorry I got to both of you so late!
appreciate you both
do you get a message saying that it refreshed (x) application commands at all?
yeah, I ended up refreshing them and they showed π
i feel like an idiot
dw it happens ^^
if you dont mind, what makes sapphire different from discord.js?
so far just looking at it, seems pretty nice but i've never heard of it before
sapphhire is just a framework built around / on-top of discord.js
ah okay
are the /routes for external routes sent by an api or anything?
in general, it makes stuff like commands and listeners much easier to implement and sapphire will handle the loading of it all for you, whereas discord.js requires you to manually do that. Most methods and structures are all still from discord.js though. E.g. User or Message
the routes folder is used when youre using
@sapphire/plugin-api
, so you can setup your own API routes for other things to use
but have sapphhire handle them too
so you could have a route "/stats" that then returns something like how many servers the bot is in and how many users its handling and then have that displayed dynamically on a websiteoh wow, that's pretty sick. I'm glad I stumbled upon this framework, i'm for sure gonna use it more often later in the future then
i could count many times where the plugin-api would have came in clutch alot π
im guessing the sapphire library is primarily based on classes?
yes, it is
ah nice
thank you thank you
youre welcome :KaydaHeart:
@KaydaFox Hey! hopefully you don't mind me pinging you, only doing so because you have conext on the whole situation
I'm trying to use
routes
and I call it from a server, I get an error
Like:
http://159.89.84.165:3001/v1/cache
I don't know if I'm doing something wrong but
Change your prefix to v1
Will do
I think, haven't used the API plugin for a long time and I'm not home rn to check code I have there
The docs for it though can be found here; https://sapphirejs.dev/docs/Guide/plugins/API/getting-started
Alright, yeah I tried checking the docs but they weren't too helpful. Just more bland
Do I need to have the
host
property on the actual server?Usually you can just set the host to 0.0.0.0 and you'll be able to use it on the current machine
If those pages are bland then please make a PR to make them better because the API docs are one of the most detailed guide pages of all pages
10 pages of loads of info...
Ah okay
No it's fine, I just have a hard time understanding the docs compared to this dudes code if that makes sense
For example, he has something like this
if my "this dude" you mean Kayda, she's a girl, not a dude π
no
I'm working on someone elses code bc they decided to quit, that's what I meant π
ah
Yeah, no avail. I'm not sure whether it might be the actual server itself or what
I didn't really read the whole convo, but is this a remote server?
port might just not be open to the publik
that's what I was gonna say
on top of which if it's an oracle vm then you need to open the thingimajig routing thing
I have a vps on digital ocean which host my bot, I've been trying to get a domain running so the sapphire routing system could work but I couldn't really get that. I then figured it'd be best try the ip itself and nothing. I have this inbound rules, so it should be receiving http/https traffic
I allowed the 3001 port through ufw
also try adding 3001 to that inbound rules list
you gotta open port 3001 there too
check if you can ping that ip in general
ufw is system level, digital coean is ingress level (I remembered the name of thingimajig now)
Alright, I assume adding this should allow inbound requests from the 3001 port:
ah didnt know that
I did
does this work or it still nay
if not send output of
sudo ufw status verbose
nope
ufw isn't active so yeah I don't think it's doing anything
do
netstat -lntu
and check if you actually have 3001 openAlright, I will do that
I guess I don't?
no
actually turn on ufw
Alright
sudo ufw enable
this will drop your ssh connection btw so make sure to add OpenSSH rules to UFW before you do
should just be sudo ufw allow OpenSSH
Alright, just did those
it's still closed
Gonna try restarting the server
sudo ufw show added
does it show the 3001?Yeah it does
huh
probably made a mistake choosing digital ocean π
seems to be working now
oh
nvm
as soon as i said that
it closed
I restarted it
Does it usaully take time for it to update the ufw settings?
maybe I'm reaching but try
sudo ufw allow 3001/tcp
Not reallyalright, I added the ufw & the server should be up now
π
still closed
normally doing stuff of digitalocean with ufw is instant, that's odd
what happens if you run
sudo netstat -tuln | grep 3001
check if the bot is listening on the port for def
the port seems completely closed considering nmap can't scan it
Nothing
and
sudo ufw status verbose
again?Is it odd that pinging the server returns this?
very
before it worked fine
I suppose it's because now
ufw
is actually on so it's denying ping requests
tbh I'd say fuck it and disable ufw
and rawdog iptables or try again with DO's interface rather than ufw
oh wait
it is working I think, it's just that ufw is blocking the pingoh, why do you say that?
its responding withh a 503 though
i forget the http codes but isnt that service unavailable?
yeah it is
because neither TCP nor ICMP pings work
So ufw seems to be blocking those
Ah
I'm using
-Pn
to kinda circumvent that but that's probably why it can't find 3001 if I had to guesswell, I tried it on postman & the browser yet connection refused for both
Can me using docker have some sort of influence on all this?
Huh, yes
can you show
docker ps
?Docker has it's own networking thing
And it does not work well with ufw firewall afaIk
yeah you're not port mapping
π
thats fun
add
-p 3001:3001
to your docker run or
to yaml
I was gonna suggest it anyway but if you would've run curl localhost:3001
on the VPS itself it also wouldnt have worked without port mappingah didnt realize they were using docker
if this doesn't work we can also try netcat ^_^
Alright, I just ran it with the
-p 3001:3001
argument. Allowing the bot to boot up nowport is open
I should've said something earlier, sorry about that π
open!
I really appreciate you all for helping me out while I get this fixed
npp
okay, i got it to return something but now it's a 404 error
wait did you put the "v1" inside of the route too?
if so try v1/v1 and then remove it from eithher the route or the prefix if it works
may have been an oversight on my part
This is everything in the api object property:
I tried running
/v1/test
, v1/v1/test
, and /test
yet to no availhm, wonder if its just not loading routes
unlikely but ive had that happen
Ive ran it on my local machine yesterday & it returned valid data, is it not loading routes still possible?
can you go into the docker container with
docker exec -it <container_name> /bin/sh
and run curl localhost:3001/v1/v1/test
and the variatns of the url?
I have a theory and if one of those works then I know why for sureAlright, I'll do so
@Boomeravna Would it normally return something?
ah add
-I
flag
also is test a real route? you showed v1/debug
before hereYeah
well can you restore the host line here?
iirc we default to localhost but localhost isn't implicitly mapped to
0.0.0.0
or 127.0.0.1
for that matter in a docker containerAlright, will do give me a minute
this will return the response headers
so you can see the status code
Ah, my bad π
Picking up on what Kayda said, could it not be loading routes?
you could try logging them ig. Do commands and listeners work?
yeah, bot works fine
add a log for
this.container.stores.get('routes')
ig
otherwise I'm a bit stumped and the fastest may be if you can share the bots code
like, a github repo or zip file
(with auth stuff being changed for placeholders ofc)the routes folder was definitely pushed there, right?
yea
src
not dist
OH
you need files in dist
let me look
yeah it is
why is routes not on the top line :thonk: ?
wdym?
I see commands, interaction-handlers, and others but no folder called routes
Oh, I shortened it
Gonna get the src
well then this tbh
@Boomeravna ^
deleted the zip because you leaked your token through the
.git
folder with unstaged changes there @staticOh
π
thanks for that
(the fact that env was even tracked by git is just bad)
(but that's beside the point rn ig)
Yeahh ik Iβm just tryna get this thing up rn
oh no
the code has prototype pollution
oh my dear lord
Blame the previous dev haha, is that bad?
yeah
discordjs used to have it natively and then it was removed in iirc v12 or v13 and some people were big mad that their shit code quality was no longer supported and they started adding extenders like those seen here
instead of accepting that they it was a code smell and they should just refactor they had to stick to it and find hacks around it instead
No wonder why his code didnβt really look like what the docs have
Prototype Pollution Prevention - OWASP Cheat Sheet Series
Website with the collection of all the cheat sheets of the project.
anyway this bot is quite complex and sadly not something I can just run myself I think. All the Rust stuff ...
:jawdroppinbro: (just reading the cheat sheet, found out its a critical vulnerability)
crap, alr I'll talk to the owner & see what I can do
I also see other stuff where I'm like "why" but I won't critique code endlessly, helps no one rn
this is surpising news ngl, Im glad you caught onto it
s!ev this.container.stores.get('routes')
Output: β± 890.26ΞΌs
anyway
it's odd that it's empty for you
at least
callback
and logout
should be there because those are part of the pluginYeah its there
this showed 0 entries tho?
can you try all those curl attempts again but with
curl -I -X POST localhost:3001/v1/callback
and the variants?I'm probably gonna make a new bot but that'll take a while & I'm guessing he wants to take the risk of the codebase currently
Alright
it should at least give a 400 bad request
π€
if I generate a bot with the CLI (complete template) and run it then I can query
curl -I -X GET localhost:3001/hello-world
just fine.
This is locally though but I have no doubts that if I'd dockerize this and map port 3001 it would work.so at least it should work
this is so stressful
what could I be doing wrong?
okay but now if I set prefixes it doesnt
hm
logging it here before i log in wouldnt affect it right
what if I remove the prefix?
granted IMHO versioning an API inside a discord bot is kind of silly anyway because you're more than likely the only consumer of the API (as in, no external users) but maybe that's not the case for this bot
oh
ahahahahah
Yeah, this was my first time ever seeing something like this but I found it cool. I know the previous dev -
is that good?
change the prefix to
/v1/
and if you keep the
v1/test
in the route (so not dropping the v1 in there) then it would've beenwow.
so prefix to
/v1/
and remove v1/
from src/routes/test.route.ts
. Then it should become :3001/v1/test
should I just keep it
/
@KaydaFox @drainpixie
since the
v1
folder?
this is very embarrasingSapphire doesn't account for folder names for the routes
only the name of the file
ah okay
@Boomeravna your amazing man, would it still work the same if I added a domain?
it should yeah, if you setup the domain routing properly ofc
btw are you using that digitalocean on a GH education plan or just paying for it out of pocket? because DO is one of the more expensive VPS providers
im asking because if this is the only thing running on it for now and you're paying for it you may want to consider switching to another provider first
:wut:
what
I'm paying out of pocket...
look at what you get for 4 euros a month for DO (left) vs Netcup (right)
I tried searching better vps yesterday, but I wasn't too sure if cheaper = worse quality & some youtuber a few years ago told me that do is what I should use
they're probably sponsored
most favoured VPS providers by youtubers are just sponsors
most of us here use Netcup
they're also EU based which is based because of EU privacy laws
do they accept USD or is it only for EU?
yes they do
dang.. wish I wasnt so gullible
you pay with paypal or credit card so it's auto converted
not sure if they support bank transfer for US residents though
nor do I know about debit cards because the US type of debit card doesnt exist in The Netherlands
ah okay, I might be able to do paypal in that case
at any rate, https://github.com/sapphiredev/plugins/pull/582
GitHub
fix(api): automatically append / to an api prefix when it's not set...
I'm not sure if this counts as a breaking change, @vladfrangu your call.
If it does count as a breaking change then I'd also like to add full file-based routing before the next major, that ...
no idea which message to mark as the answer tho
Any other alternatives? I guess I need to wait for them to verify my details
all providers should have to wait for verification because you're engaging in a legally binding contract. Any provider that doesn't verify is an automatic red flag
glad that this is getting added!
really? out of curiosity, how come digital ocean never does?
something something big corpo's get away with scummy business practises, thanks capatalism something something
ah makes sense
how long does it usaully take to be approved?
bout a day at most
it's nearly 12 am for Austria right now so give it maybe 12ish hours at minimum
ah alright
@Boomeravna quick question, is there anything specific on the docs for configuring domain names? I know with nginx you'd need to but was curious how sapphire automatically handles that
sapphire doesnt
it's all server side stuff
alright good to know
appreciate you all
@Boomeravna last question, would changing the port to 3000 be the main port?
wdym?
like, instead of having to do
http://159.89.84.165:3001/v1/test
could I change it to http://159.89.84.165/v1/test
? I'm trying to change it to work on a domain & I'm not too skilled in networking, I can't seem to have the IP of the a record point to 3001
nvm
might be something for nginxthe default http port is port 80
anyway just learn how nginx reverse proxying works, for example https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-reverse-proxy-on-ubuntu-22-04
How To Configure Nginx as a Reverse Proxy on Ubuntu 22.04 | Digital...
This tutorial will demonstrate how to set up a reverse proxy using Nginx, a popular web server and reverse proxy solution. You will install Nginx, configure β¦
also I recommend putting the domain behind a Cloudflare DNS so you can secure it with SSL. Not having HTTPS in anno 2024 is just plain bad.
yeah, i was just gonna use lets encrypt, I had an issue getting cloudflare actually work with my ip
and now i got it working
just assumed the entire issue was a cloudflare issue
but thanks
Quick question
Is this the right route?
Returns null
however test returns this
Remove the leading slash, because you added it to prefix you're now creating //
Sorry for me constantly bugging you, but I got it to work for the tickets route, however doesn't seem to work for the sellapp
compared to sellapp
same everything
nvm..