Skip to main content

Official Python SDK for the Vega API (Discord giveaways).

Project description

vegabot-py-sdk (Python)

Official Python SDK for the Vega API — Discord giveaways, required-server management, and the membership gate. Included with a Vega whitelabel license.

pip install vegabot-py-sdk

Python 3.9+.

Quick start

import os
from vega import VegaClient

vega = VegaClient(api_key=os.environ["VEGA_API_KEY"])

me = vega.me()                 # {"guildId": ..., "license": {...}}
active = vega.list_giveaways()

Get your key from the dashboard: Whitelabel → API → Generate key (license owner only). A key is scoped to one Discord server. Keep it server-side. Use the client as a context manager to auto-close:

with VegaClient(api_key=...) as vega:
    vega.list_giveaways()

Giveaways

res = vega.create_giveaway(
    prize="Nitro",
    channel_id="123456789012345678",
    duration_seconds=86_400,
    winners=1,
    description="Good luck!",
    requirements=[{"requiredGuildId": "987654321098765432"}],
)

active = vega.list_giveaways()
one = vega.get_giveaway(res["giveawayId"])     # {"giveaway":..., "entryCount":..., "winnerIds":[...]}
vega.end_giveaway(res["giveawayId"])
vega.reroll_giveaway(res["giveawayId"], winners=2)

Required servers

vega.register_server(required_guild_id="987...", name="Main Server", invite_url="https://discord.gg/abc")
servers = vega.list_servers()
vega.delete_server("987...")

Membership gate

result = vega.check_membership(user_id="111...", required_guild_id="987...")
print(result["inServer"], result["hasRole"])

Settings

settings = vega.get_settings()

Reacting to giveaway events

Two options: poll (no public URL) or receive webhooks.

Option A — polling (no public URL needed)

listen polls the event feed and calls your handler for each event, in order. It blocks, so run it in a thread.

import threading

def handle(event):
    if event["event"] == "giveaway.ended":
        print("winners", event["data"]["winnerIds"])

stop = threading.Event()
threading.Thread(target=vega.listen, args=(handle,), kwargs={"stop": stop}, daemon=True).start()
# ... later: stop.set()

By default only events after listen starts are delivered; pass after=0 to replay everything still in the feed. You can also poll manually with vega.list_events(after, limit) and track the last id.

Option B — webhooks

Set a delivery URL (dashboard API → Webhooks, or vega.set_webhook(url)). Vega POSTs signed events to it. Verify the X-Vega-Signature header. construct_event verifies and parses in one call:

from vega import construct_event, VegaSignatureError

# Flask, needs the RAW body
@app.post("/vega/webhook")
def webhook():
    try:
        event = construct_event(request.get_data(), request.headers.get("X-Vega-Signature"), SECRET)
    except VegaSignatureError:
        return "", 401
    if event["event"] == "giveaway.ended":
        print(event["data"]["winnerIds"])
    return "", 200

Prefer verifying yourself? Use verify_webhook(raw_body: bytes, header, secret) -> bool.

See examples/ for Flask, FastAPI, and polling.

Errors

Failed calls raise VegaApiError with .status, .code, and .detail.

from vega import VegaApiError
try:
    vega.get_giveaway(999999)
except VegaApiError as e:
    if e.status == 404:
        print("not found")

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vegabot_py_sdk-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vegabot_py_sdk-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file vegabot_py_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: vegabot_py_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vegabot_py_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4ab014cf8802882882ab31b78c6cc599df8180d42285c64c11c59f92cc0550f2
MD5 79eb6d38d3a839f08572a8695f479cf8
BLAKE2b-256 b1563a15ff75aa082471758be642b4c3b59c68711f9b4a9a2417534492e38751

See more details on using hashes here.

Provenance

The following attestation bundles were made for vegabot_py_sdk-0.1.0.tar.gz:

Publisher: publish.yml on Vega-Discord-Bot/vega-sdk-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vegabot_py_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: vegabot_py_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vegabot_py_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 595674a988c054ce9ac2c9cbbcf28ed7c1d131f7b97a5e48c002d33c235da36c
MD5 cb9a9009790ffa79a1426b683c8d5467
BLAKE2b-256 5f04fd6b49f43750923606e84cc6bdd03e83068556cf7efe748c05d58f4c9513

See more details on using hashes here.

Provenance

The following attestation bundles were made for vegabot_py_sdk-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Vega-Discord-Bot/vega-sdk-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page