rewrite init + member count api

This commit is contained in:
2022-12-16 09:30:42 +01:00
parent 9df1e896c6
commit 77c1f0f664
7 changed files with 1894 additions and 0 deletions

6
src/cfg.json Normal file
View File

@@ -0,0 +1,6 @@
{
"api": {
"fallbackPort": 2020,
"memberCountGuildId": "447075692664979466"
}
}

30
src/index.ts Normal file
View File

@@ -0,0 +1,30 @@
import DiscordJS from 'discord.js';
// import fs from 'fs';
import express from 'express';
import dotenv from 'dotenv';
import config from './cfg.json';
dotenv.config();
const client = new DiscordJS.Client({
intents: [DiscordJS.GatewayIntentBits.Guilds],
});
const app = express();
const port = process.env.PORT || config.api.fallbackPort;
app.get('/', (req, res) => {
res.sendStatus(200);
});
app.get('/members', (req, res) => {
res.send(
client.guilds.resolve(config.api.memberCountGuildId)?.memberCount.toString()
);
});
client.on('ready', () => {
console.log(`BOT: Now logged in as ${client.user?.tag}.`);
});
const api = app.listen(port, () => {
console.log(`API: Now listening on :${port}.`);
});
client.login(process.env.TOKEN);