Is there a Example on how to work with the API Plugin directly in the bot?

I want to try out how that is working, is there an example Repository somewhere? Because the Docs are super limited.
Solution:
thats correct
No description
Jump to solution
43 Replies
chillihero
chilliheroOP2y ago
great thanks, but its still not mentioned how I can access the routes in the browser then
Photon
Photon2y ago
you access the routes on the port on which your server is running
chillihero
chilliheroOP2y ago
what If I run it on local?
Photon
Photon2y ago
localhost:port
chillihero
chilliheroOP2y ago
yea but there is no port... I just start the bot?
Himori
Himori2y ago
there is currently no file which specifies a webserver
Himori
Himori2y ago
and no mention in the documents of how to use the routes besides them existing https://www.sapphirejs.dev/docs/Guide/plugins/API/getting-started There is example code but it doesn't mention how and where to use it
Photon
Photon2y ago
It's a plugin, you don't need to define any webserver for it it just need to be registered something like import '@sapphire/plugin-api/register'; in the core of your bot and done
Himori
Himori2y ago
I'm confused
Photon
Photon2y ago
on?
Himori
Himori2y ago
I'm essentially just going through the documentation but it never even mentions that
chillihero
chilliheroOP2y ago
OHHH
chillihero
chilliheroOP2y ago
this?
Photon
Photon2y ago
It mentions as pointed in snap ^ A plugin should always be registered
Himori
Himori2y ago
if thats it then I feel so dumb right now. Not added any data to it yet
Photon
Photon2y ago
I will have to test myself, I never used that plugin before
Photon
Photon2y ago
Photon
Photon2y ago
works for me
Photon
Photon2y ago
This is all what I changed
Himori
Himori2y ago
wow
chillihero
chilliheroOP2y ago
when I add the values to my Sapphire Client Object I recieve a Error
chillihero
chilliheroOP2y ago
it says that SapphireClient has no argument listenOptions
chillihero
chilliheroOP2y ago
Solution
chillihero
chillihero2y ago
thats correct
No description
Himori
Himori2y ago
wait I'm not using the api parameter, why does it still work?
chillihero
chilliheroOP2y ago
you are not using ts
Photon
Photon2y ago
because you didn't registered the plugin
chillihero
chilliheroOP2y ago
I did bruh
chillihero
chilliheroOP2y ago
here
chillihero
chilliheroOP2y ago
it needs the API obj now it works
Photon
Photon2y ago
yeah
Himori
Himori2y ago
is there a method that gets executed on every incoming web request?
chillihero
chilliheroOP2y ago
How is it possible to send a Discord Message when a API Route is called?
Photon
Photon2y ago
for you both, use middleware
Himori
Himori2y ago
do you want to tell me that we can just use express in it?
chillihero
chilliheroOP2y ago
is there a example for this somewhere?
Photon
Photon2y ago
No example, you can have a look at source code
chillihero
chilliheroOP2y ago
well its not done in any repository i looked at so far
Favna
Favna2y ago
No, plugin-api doesn't use express. It uses node's http The plugin would be a total laughing stock if it would use express
Himori
Himori2y ago
😄 just checking: To what point is Sapphire compatible with discordjs code? lets say command files
Favna
Favna2y ago
Sapphire is a framework on top of discordjs You literally cannot use sapphire without discordjs So to what extend? 100%
Himori
Himori2y ago
👍🏻
Want results from more Discord servers?
Add your server