const https = require("https"); const discord = require("discord.js"); require("dotenv").config(); const client = new discord.Client({ intents: [ discord.GatewayIntentBits.Guilds, discord.GatewayIntentBits.GuildMessages, discord.GatewayIntentBits.DirectMessages, discord.GatewayIntentBits.MessageContent, ], }); //client.on("ready", () => client.channels.cache.get("1149301234046607442").send("test")); client.on("ready", () => console.log("READY")); client.on("messageCreate", async message => { if (message.author.bot) return; switch (message.content) { case "!serenity": const result = []; for (user of ["reimarpb", "simonfj20"]) { const response = await request("GET", "https://api.github.com/search/issues?q=author:" + user + "+repo:serenityos/serenity+is:closed"); result.push({ user, count: response.total_count, }); } result.sort((a, b) => b.count - a.count); let str = "**Sejheds-indeks:**\n"; for (obj of result) { str += obj.user + ": " + obj.count + "\n"; } message.channel.send(str); break; } }); client.login(process.env.TOKEN); function request(method, url) { return new Promise(resolve => { const options = { method, headers: { "User-Agent": "ReimarPB", }, }; const req = https.request(url, options, res => { let data = ""; res.on("data", chunk => data += chunk); res.on("end", () => { resolve(JSON.parse(data)); }); }); req.end(); }); }