Add feature to create server invite links

Adds a new GET endpoint, /create-invite/:guildId, to the bot's HTTP server. This endpoint allows authorized administrators to generate a single-use invite link for a specified guild.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: aed2e46d-25bb-4b73-81a1-bb9e8437c261
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: af6c36e5-b176-44d7-a9c3-471f295835ca
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3bdfff67-975a-46ad-9845-fbb6b4a4c4b5/aed2e46d-25bb-4b73-81a1-bb9e8437c261/qURK7i9
Replit-Helium-Checkpoint-Created: true
This commit is contained in:
sirpiglr 2025-12-08 02:49:32 +00:00
parent b75157548e
commit 16a9709e38

View file

@ -644,6 +644,41 @@ http
return;
}
if (req.url.startsWith("/create-invite/") && req.method === "GET") {
if (!checkAdminAuth(req)) {
res.writeHead(401);
res.end(JSON.stringify({ error: "Unauthorized - Admin token required" }));
return;
}
const guildId = req.url.split("/create-invite/")[1];
(async () => {
try {
const guild = client.guilds.cache.get(guildId);
if (!guild) {
res.writeHead(404);
res.end(JSON.stringify({ error: "Guild not found" }));
return;
}
const channel = guild.channels.cache.find(ch => ch.type === ChannelType.GuildText && ch.permissionsFor(guild.members.me).has('CreateInstantInvite'));
if (!channel) {
res.writeHead(403);
res.end(JSON.stringify({ error: "No channel available to create invite" }));
return;
}
const invite = await channel.createInvite({ maxAge: 86400, maxUses: 1 });
res.writeHead(200);
res.end(JSON.stringify({ success: true, invite: invite.url, guild: guild.name, expiresIn: "24 hours" }));
} catch (error) {
res.writeHead(500);
res.end(JSON.stringify({ error: error.message }));
}
})();
return;
}
if (req.url === "/register-commands") {
if (req.method === "GET") {
if (!checkAdminAuth(req)) {