# TUTORIAL & STEPS

## 🔐 K1WI.XYZ API & Protection Module

Welcome to the official documentation for the **K1WI.XYZ API** and the **Anti‑Nuke / Anti‑Raid Protection Module**.\
This system allows you to obtain a personal API key, generate a custom protection module for your own Discord bot, and interact with real‑time protection data.

***

### 📦 Overview

The K1WI.XYZ ecosystem provides:

* **API Keys** – Unique credentials tied to your Discord account.
* **Referral Codes** – One‑time codes used to claim an API key.
* **Protection Module** – A ready‑to‑use JavaScript file that adds anti‑nuke and anti‑raid capabilities to any Discord.js v14 bot.
* **Public API Endpoints** – Securely query the status of anti‑nuke/anti‑raid, logs, backups, and more.

***

### 🌐 Step 1 – Get a Referral Code

Before you can claim an API key, you need a **referral code**.

1. Visit the referral generator page:\
   <https://docs.k1wi.xyz/link/generator>
2. The page will display a unique referral code (e.g. `*****-*****-*****-*****-*****-*****`).
3. Copy the code to your clipboard.

> **Note:** Each referral code has a **24‑hour cooldown** after being redeemed. If a code is on cooldown, the page will show another available one.

***

### 🤖 Step 2 – Redeem the Code on Discord

Use the **Discord bot** to claim your personal API key.

#### Command: `/redeemapi`

**`/redeemapi code:<your-referral-code>`**

**Requirements:**

* You must **not** already have an API key.
* The referral code must be valid and not on cooldown.

**What happens:**

* The bot verifies the code.
* If valid, it generates a **unique API key** (UUID v4) and saves it linked to your Discord ID.
* The referral code enters a 24‑hour cooldown.
* Your API key is shown **only once** – copy and save it immediately!

**Example:**\
\&#xNAN;**`/redeemapi code:*****-*****-*****-*****-*****-*****`**

**Response:**

> ✅ API Key Generated!\
> Your personal API key:\
> `a1b2c3d4-e5f6-7890-abcd-ef1234567890`\
> Keep it safe! You can retrieve it later with `/myapi`.

***

### 🔑 Step 3 – Manage Your API Key

#### Command: `/myapi`

If you ever forget your API key, use this command to see it again.

**`/myapi`**

**Response:**\
An ephemeral message containing your API key.

***

### 📥 Step 4 – Generate Your Protection Module

The **protection module** is a JavaScript file that you can add to your own Discord.js bot. It contains the same anti‑nuke and anti‑raid logic used by K1WI.XYZ, **stripped of custom emojis** and ready to be integrated.

#### Command: `/generatecode`

**`/generatecode`**

**Requirements:**

* You must have a valid API key (obtained via `/redeemapi`).

**What happens:**

* The bot creates a file named `protection.js`.
* The file is sent to your **Direct Messages** (DM) as an attachment.
* If your DMs are closed, you will receive an error message in the channel.

> **⚠️ The file is unique to your account and contains your API key watermark. Do not share it publicly.**

***

### 🛠️ Step 5 – Install the Protection Module

#### 1. Place the file in your bot project

Move `protection.js` into your bot’s main directory (e.g., alongside your `index.js` or `bot.js`).

#### 2. Require the module in your main file

At the top of your main bot file, add:

```javascript
require('./protection.js')(client);
```

#### 3. Required Intents

The module needs the following intents enabled on your client:

```javascript
const { Client, GatewayIntentBits } = require('discord.js');

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

#### 4. Implement a Settings System

The module expects each guild to have a `settings` object attached.\
You must provide:

```
guild.settings = {
antiNuke: { enabled: true }, // boolean – enable/disable anti‑nuke
antiRaid: { enabled: true }, // boolean – enable/disable anti‑raid
logChannel: '123456789012345678' // Snowflake – channel ID for logs (optional)
};
```

**Example:** If you already use a database or JSON configuration, assign `guild.settings` after fetching the guild.

#### 5. Restart your bot

Once the file is required and settings are in place, restart your bot. You should see a console message:

```
[Protection] Anti-Nuke & Anti-Raid module loaded for YourBotName#1234
```

The protection is now active.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://danidema.gitbook.io/k1wi.xyz/documentation/api-bot-discord/tutorial-and-steps.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
