Skip to content

Commit 01d5b25

Browse files
committed
fix: port already in use crashing the bot
1 parent c6b3a59 commit 01d5b25

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

bot.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,27 @@ fs.readdirSync('./events').filter(file => file.endsWith('.js')).forEach(async (f
1515
// Start the bot
1616
client.login(process.env.TOKEN)
1717

18-
// start the API
19-
const app = express()
20-
const PORT = process.env.EXPRESS_PORT || 3001
21-
22-
app.put('/users/:id/roles', async (req, res) => {
23-
const { id } = req.params
24-
const { remove } = req.query
25-
await updateRoles(client, id, null, remove === 'true')
26-
27-
res.status(200).send()
28-
})
29-
30-
app.get('/guilds', async (req, res) => {
31-
const guilds = client.guilds.cache
32-
res.status(200).json(guilds)
33-
})
34-
35-
app.listen(PORT, () => {
36-
console.log(`🐉 API server is running on port ${PORT}`)
37-
})
18+
try {
19+
// start the API
20+
const app = express()
21+
const PORT = process.env.EXPRESS_PORT || 3001
22+
23+
app.put('/users/:id/roles', async (req, res) => {
24+
const { id } = req.params
25+
const { remove } = req.query
26+
await updateRoles(client, id, null, remove === 'true')
27+
28+
res.status(200).send()
29+
})
30+
31+
app.get('/guilds', async (req, res) => {
32+
const guilds = client.guilds.cache
33+
res.status(200).json(guilds)
34+
})
35+
36+
app.listen(PORT, () => {
37+
console.log(`🐉 API server is running on port ${PORT}`)
38+
})
39+
} catch (error) {
40+
console.error('Failed to start the API server:', error)
41+
}

0 commit comments

Comments
 (0)