{
  "openapi": "3.1.0",
  "info": {
    "title": "Picked.gg API",
    "version": "1.0.0",
    "description": "Everything under /api/v1 acts on one listing: the token identifies the bot, and the id in the path has to be that same bot. A mismatch answers 404 rather than 403, so a token cannot be used to discover which other bots exist.",
    "contact": { "name": "Support", "url": "https://picked.gg/contact" },
    "license": { "name": "Terms of Service", "url": "https://picked.gg/legal/terms" }
  },
  "servers": [{ "url": "https://picked.gg", "description": "Production" }],
  "security": [{ "botToken": [] }],
  "components": {
    "securitySchemes": {
      "botToken": {
        "type": "apiKey",
        "in": "header",
        "name": "Authorization",
        "description": "The bot's API token, generated on its edit page. Sent bare or as `Bearer <token>` -- both are accepted, because the libraries already posting to other lists send both. The token is shown once; generating a new one invalidates the old."
      }
    },
    "parameters": {
      "botId": {
        "name": "id",
        "in": "path",
        "required": true,
        "description": "The bot's Discord application id. It has to be the bot the token belongs to.",
        "schema": { "type": "string", "pattern": "^\\d{17,19}$" },
        "example": "1092194789458481202"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": { "type": "string", "description": "One sentence, safe to show a developer." },
          "retryAfter": { "type": "integer", "description": "Seconds until the limit resets. Only on 429." }
        },
        "required": ["error"]
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing, malformed or unknown token.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "example": { "error": "Invalid token." }
          }
        }
      },
      "NotFound": {
        "description": "No such bot, or the token belongs to a different one.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "example": { "error": "Bot not found." }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limit exceeded.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "example": { "error": "Rate limit exceeded.", "retryAfter": 42 }
          }
        }
      },
      "BadRequest": {
        "description": "The body or a query parameter is malformed.",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/Error" },
            "example": { "error": "Invalid JSON body." }
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/bots/{id}/stats": {
      "post": {
        "operationId": "postServerCount",
        "summary": "Post the Server Count",
        "description": "Report how many servers the bot is in. Rate limit: 60 requests per minute per token, which is well above one post per shard per interval.\n\nRe-posting the same number is cheap: the page cache is only invalidated when the value actually changes. The check-in timestamp is written every time, and it is what the bot page reads as a liveness signal.",
        "tags": ["Bot"],
        "x-codeSamples": [
          { "lang": "bash", "label": "cURL", "source": "curl -X POST https://picked.gg/api/v1/bots/YOUR_BOT_ID/stats \\\n  -H \"Authorization: YOUR_API_TOKEN\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"server_count\": 1482}'" },
          { "lang": "javascript", "label": "discord.js", "source": "client.once(Events.ClientReady, async () => {\n  await fetch(`https://picked.gg/api/v1/bots/${client.user.id}/stats`, {\n    method: 'POST',\n    headers: {\n      Authorization: process.env.PICKED_TOKEN,\n      'Content-Type': 'application/json',\n    },\n    body: JSON.stringify({ server_count: client.guilds.cache.size }),\n  });\n});" },
          { "lang": "python", "label": "discord.py", "source": "import os, aiohttp\n\n@bot.event\nasync def on_ready():\n    async with aiohttp.ClientSession() as session:\n        await session.post(\n            f\"https://picked.gg/api/v1/bots/{bot.user.id}/stats\",\n            headers={\"Authorization\": os.environ[\"PICKED_TOKEN\"]},\n            json={\"server_count\": len(bot.guilds)},\n        )" }
        ],
        "parameters": [{ "$ref": "#/components/parameters/botId" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "One of the three field names is required. They are aliases; server_count is the canonical one and the other two exist because SDKs in the wild send them.",
                "properties": {
                  "server_count": { "type": "integer", "minimum": 0, "maximum": 100000000 },
                  "serverCount": { "type": "integer", "minimum": 0, "maximum": 100000000 },
                  "guildCount": { "type": "integer", "minimum": 0, "maximum": 100000000 }
                }
              },
              "example": { "server_count": 1482 }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stored.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "server_count": { "type": "integer" }
                  }
                },
                "example": { "success": true, "server_count": 1482 }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/api/v1/bots/{id}/commands": {
      "put": {
        "operationId": "putCommands",
        "summary": "Publish the Commands",
        "description": "Replace the commands shown on the bot's page. PUT rather than POST on purpose: a bot that removed a command has to be able to say so, and a merge would leave the removed one on the page with nothing able to delete it.\n\nThe shape mirrors Discord's own application command objects, so a bot can forward what it already registered. Duplicate names are dropped, keeping the first. An empty array clears the list. Rate limit: 10 requests per minute per token -- enough to clear a restart loop, not a stream.",
        "tags": ["Bot"],
        "x-codeSamples": [
          { "lang": "bash", "label": "cURL", "source": "curl -X PUT https://picked.gg/api/v1/bots/YOUR_BOT_ID/commands \\\n  -H \"Authorization: YOUR_API_TOKEN\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"commands\": [{\"name\": \"ban\", \"description\": \"Ban a member\"}]}'" },
          { "lang": "javascript", "label": "discord.js", "source": "client.once(Events.ClientReady, async () => {\n  const registered = await client.application.commands.fetch();\n  const commands = registered.map((c) => ({ name: c.name, description: c.description }));\n\n  await fetch(`https://picked.gg/api/v1/bots/${client.user.id}/commands`, {\n    method: 'PUT',\n    headers: {\n      Authorization: process.env.PICKED_TOKEN,\n      'Content-Type': 'application/json',\n    },\n    body: JSON.stringify({ commands }),\n  });\n});" },
          { "lang": "python", "label": "discord.py", "source": "import os, aiohttp\n\n@bot.event\nasync def on_ready():\n    commands = [\n        {\"name\": c.name, \"description\": c.description}\n        for c in bot.tree.get_commands()\n    ]\n    async with aiohttp.ClientSession() as session:\n        await session.put(\n            f\"https://picked.gg/api/v1/bots/{bot.user.id}/commands\",\n            headers={\"Authorization\": os.environ[\"PICKED_TOKEN\"]},\n            json={\"commands\": commands},\n        )" }
        ],
        "parameters": [{ "$ref": "#/components/parameters/botId" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["commands"],
                "properties": {
                  "commands": {
                    "type": "array",
                    "maxItems": 100,
                    "items": {
                      "type": "object",
                      "required": ["name", "description"],
                      "properties": {
                        "name": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 32,
                          "description": "Discord's own bound: a list Discord accepted is a list this accepts."
                        },
                        "description": { "type": "string", "minLength": 1, "maxLength": 100 }
                      }
                    }
                  }
                }
              },
              "example": {
                "commands": [
                  { "name": "ban", "description": "Ban a member" },
                  { "name": "warn", "description": "Warn a member and log it" }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stored. count is what survived de-duplication.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "count": { "type": "integer" }
                  }
                },
                "example": { "success": true, "count": 2 }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/api/v1/bots/{id}/check": {
      "get": {
        "operationId": "checkVote",
        "summary": "Check a User Vote",
        "description": "Answers whether a user is inside their current 12-hour vote window. This is the endpoint that makes vote-for-perks possible, so its limit is the highest on the API: 600 requests per minute per token.\n\n`voted` is 0 or 1 because that is what bot code written against other lists expects; `hasVoted` is the readable alias for new code. `nextVoteAt` lets the bot tell the user when to come back without recomputing the cooldown.",
        "tags": ["Votes"],
        "x-codeSamples": [
          { "lang": "bash", "label": "cURL", "source": "curl \"https://picked.gg/api/v1/bots/YOUR_BOT_ID/check?userId=336878018143223809\" \\\n  -H \"Authorization: YOUR_API_TOKEN\"" },
          { "lang": "javascript", "label": "discord.js", "source": "async function hasVoted(interaction) {\n  const response = await fetch(\n    `https://picked.gg/api/v1/bots/${interaction.client.user.id}/check?userId=${interaction.user.id}`,\n    { headers: { Authorization: process.env.PICKED_TOKEN } }\n  );\n  const vote = await response.json();\n  return vote.hasVoted;\n}" },
          { "lang": "python", "label": "discord.py", "source": "import os, aiohttp\n\nasync def has_voted(interaction: discord.Interaction) -> bool:\n    async with aiohttp.ClientSession() as session:\n        async with session.get(\n            f\"https://picked.gg/api/v1/bots/{interaction.client.user.id}/check\",\n            params={\"userId\": str(interaction.user.id)},\n            headers={\"Authorization\": os.environ[\"PICKED_TOKEN\"]},\n        ) as response:\n            return (await response.json())[\"hasVoted\"]" }
        ],
        "parameters": [
          { "$ref": "#/components/parameters/botId" },
          {
            "name": "userId",
            "in": "query",
            "required": true,
            "description": "The Discord user id to look up.",
            "schema": { "type": "string", "pattern": "^\\d{17,20}$" },
            "example": "336878018143223809"
          }
        ],
        "responses": {
          "200": {
            "description": "The user's vote state for this bot.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "voted": { "type": "integer", "enum": [0, 1] },
                    "hasVoted": { "type": "boolean" },
                    "votedAt": { "type": ["string", "null"], "format": "date-time" },
                    "nextVoteAt": {
                      "type": ["string", "null"],
                      "format": "date-time",
                      "description": "12 hours after the vote. Null when the user has not voted inside the window."
                    }
                  }
                },
                "example": {
                  "voted": 1,
                  "hasVoted": true,
                  "votedAt": "2026-09-12T08:15:00.000Z",
                  "nextVoteAt": "2026-09-12T20:15:00.000Z"
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/api/v1/bots/{id}/votes": {
      "get": {
        "operationId": "listVotes",
        "summary": "Recent Votes",
        "description": "The vote log, newest first. Read from the append-only event log rather than the one-row-per-user table, which is the only place the history exists.\n\nUser ids and timestamps and nothing else: the caller already shares a server with these people, and returning names or avatars would turn a vote lookup into a profile scrape. Rate limit: 60 requests per minute per token.",
        "tags": ["Votes"],
        "x-codeSamples": [
          { "lang": "bash", "label": "cURL", "source": "curl \"https://picked.gg/api/v1/bots/YOUR_BOT_ID/votes?limit=100\" \\\n  -H \"Authorization: YOUR_API_TOKEN\"" },
          { "lang": "javascript", "label": "discord.js", "source": "const response = await fetch(\n  `https://picked.gg/api/v1/bots/${client.user.id}/votes?limit=100`,\n  { headers: { Authorization: process.env.PICKED_TOKEN } }\n);\nconst { votes } = await response.json();\n\nfor (const vote of votes) {\n  if (Date.parse(vote.voted_at) <= lastSeen) break; // newest first\n  await grantReward(vote.user_id);\n}" },
          { "lang": "python", "label": "discord.py", "source": "import os, aiohttp\n\nasync with aiohttp.ClientSession() as session:\n    async with session.get(\n        f\"https://picked.gg/api/v1/bots/{bot.user.id}/votes\",\n        params={\"limit\": 100},\n        headers={\"Authorization\": os.environ[\"PICKED_TOKEN\"]},\n    ) as response:\n        votes = (await response.json())[\"votes\"]\n\nfor vote in votes:\n    if vote[\"voted_at\"] <= last_seen:  # newest first, same ISO format\n        break\n    await grant_reward(int(vote[\"user_id\"]))" }
        ],
        "parameters": [
          { "$ref": "#/components/parameters/botId" },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "1 to 100. Anything outside the range is clamped rather than refused.",
            "schema": { "type": "integer", "minimum": 1, "maximum": 100, "default": 50 }
          }
        ],
        "responses": {
          "200": {
            "description": "The most recent votes.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "votes": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "user_id": { "type": "string" },
                          "voted_at": { "type": "string", "format": "date-time" }
                        }
                      }
                    }
                  }
                },
                "example": {
                  "votes": [
                    { "user_id": "336878018143223809", "voted_at": "2026-09-12T08:15:00.000Z" }
                  ]
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/api/v1/bots/{id}/widget": {
      "get": {
        "operationId": "voteWidget",
        "summary": "Vote Count Badge",
        "description": "An embeddable badge, public and unauthenticated: the point is to be pasted into a README where no credential can be kept, and it exposes only the vote count, which is already on the public bot page.\n\nA hidden or unknown bot still gets a badge reading `unknown` rather than a 404 -- a broken image in somebody's README is the worse outcome. Cached for 5 minutes.",
        "tags": ["Public"],
        "x-codeSamples": [
          { "lang": "bash", "label": "cURL", "source": "curl https://picked.gg/api/v1/bots/YOUR_BOT_ID/widget" },
          { "lang": "markdown", "label": "Markdown", "source": "![Votes](https://picked.gg/api/v1/bots/YOUR_BOT_ID/widget)" }
        ],
        "security": [],
        "parameters": [{ "$ref": "#/components/parameters/botId" }],
        "responses": {
          "200": {
            "description": "An SVG badge.",
            "content": { "image/svg+xml": { "schema": { "type": "string" } } }
          }
        }
      }
    }
  }
}
