Create WebServer with Plugin API

Hello ! I read the doc for install a webserver in my bot. Here my code:
const client = new SapphireClient({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildVoiceStates],
prefix: '',
origin: '*',
listenOptions: {
port: 8080
}
});
const client = new SapphireClient({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildVoiceStates],
prefix: '',
origin: '*',
listenOptions: {
port: 8080
}
});
These lines should open a web server on 8080 port, no ?
Solution:
OK, that's it. He didn't like port 8080...
Jump to solution
9 Replies
Favna
Favna13mo ago
Assuming you have the line to register the api plugin somewhere, yes. You need to have this somewhere in your entrypoint. And add the dependency of course.
import '@sapphire/plugin-api/register'
import '@sapphire/plugin-api/register'
Mathias
MathiasOP13mo ago
Yes I have
Favna
Favna13mo ago
Then yes there should be a web server. There is no default route other than /oauth/login though so if you were testing with / you'd get 404
Mathias
MathiasOP13mo ago
I get ERR_CONNECTION_REFUSED My web server is not " open "
Solution
Mathias
Mathias13mo ago
OK, that's it. He didn't like port 8080
Favna
Favna13mo ago
maybe something else was already running on it
Favna
Favna13mo ago
btw those options you have there is invalid. It should be nested under an api key:
const client = new SapphireClient({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildVoiceStates],
api: {
prefix: '',
origin: '*',
listenOptions: {
port: 8080
}
}
});
const client = new SapphireClient({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildVoiceStates],
api: {
prefix: '',
origin: '*',
listenOptions: {
port: 8080
}
}
});
also prefix: '' and origin: '*' are the default
Mathias
MathiasOP13mo ago
Thank you!
kyra
kyra13mo ago
For further clarification, the port 8080 is also the HTTP default port (:80/:8080, HTTPS is :443). This is also the port used by Nginx or Apache which come pre-installed in many servers, so naturally because that port is used, it fails. The idea with Nginx or Apache is that you can use them as a reverse proxy instead of exposing those ports directly, which comes with many benefits, but that's a more complex topic (and unrelated to this, but you can ask in #off-topic!)
Want results from more Discord servers?
Add your server