EXAMPLES/BASIC-USAGE.JS

Basic Usage

This is a full minimal bot - client creation included - copied directly from the library's examples/ folder. Use it if you're starting completely from scratch instead of attaching GlassFrame to a bot you already have running.

"use strict";

const { Client, GatewayIntentBits } = require("discord.js");
const GlassFrame = require("glassframe-protocol");

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
    GatewayIntentBits.GuildModeration
  ]
});

client.once("ready", () => {
  const frame = new GlassFrame(client, {
    getLogChannel: async (guild) => {
      return guild.channels.cache.find((c) => c.name === "security-logs") ?? null;
    },
    whitelist: [],
    // Layers not listed here stay off until someone presses the panel button
    // or you call frame.enableLayer(name) yourself.
    autoStart: ["basicSecurity", "antiRaid", "antiNuke"],
    debug: false,
    config: {
      aiModeration: {
        // Supply one key or several - GlassFrame rotates across the pool and
        // benches any key that comes back rate-limited.
        apiKeys: (process.env.GROQ_API_KEYS || "").split(",").filter(Boolean)
      }
    }
  });

  frame.on("warning", (w) => console.warn(`[GlassFrame:${w.layer}]`, w.message));
  frame.punishmentEngine.on("case", (record) => {
    console.log(`[GlassFrame] ${record.action} on ${record.userId} (tier ${record.tier})`);
  });

  console.log(`GlassFrame Protocol ready in ${client.guilds.cache.size} guild(s).`);
  console.log('Send "!gf panel" in a channel (Manage Server permission) to open the control panel.');
});

client.login(process.env.BOT_TOKEN);