Skip to main content

Core python library for interfacing with Discolytics APIs

Project description

1. Installation

pip install discolytics

2. Get API Key

Under the API Keys tab of your dashboard, create a new API key. Copy this key and your bot ID to connect within your codebase.

3. Example Usage

Initiate the client library in your codebase. Enter your bot ID and API key from the previous step to connect, as well as your bot token under the auth option.

Your bot token is never sent to Discolytics servers. It is used by our client libraries on your machine to make requests to Discord on your behalf for metadata and analytics (such as to request your bot profile, guild count, etc).

import discord
import os
from dotenv import load_dotenv
from discolytics import Discolytics
from time import sleep
import json

load_dotenv()

# initiate Discolytics client
discolytics = Discolytics({
    'api_key': os.getenv('DISCOLYTICS_KEY'),
    'auth': os.getenv('TOKEN'),
    'bot_id': 'YOUR_BOT_ID',
    'cluster_id': 0 # if clustering, provide the current cluster ID
})

client = discord.Client(intents=discord.Intents.all(), enable_debug_events=True)

@client.event
async def on_ready():
    print(f'Client ready as {client.user}')

    # post shards to discolytics
    discolytics.post_shards({'id': 0, 'status': 'ready', "latency": 1})

    # discolytics.start_command returns a function. Run this function once the command ends. guild_id is optional.
    end_command = discolytics.start_command(name='help', user_id='123', guild_id='123')
    sleep(5)
    # run end_command once the command ends
    end_command()

# send events to Discolytics
@client.event
async def on_socket_raw_receive(raw_msg):
    if not isinstance(raw_msg, str):
            return
    msg = json.loads(raw_msg)
    event_type = msg.get("t")
    data = msg.get("d")
    if not data or not event_type:
        return

    guild_id = data.pop('guild_id', None)
    discolytics.send_event(name=event_type, guild_id=guild_id)

    # send interactions to discolytics
    if event_type == 'INTERACTION_CREATE':
        type = data.pop('type', None)
        if not type:
            return
        discolytics.post_interaction(type=type, guild_id=guild_id)

client.run(os.getenv('TOKEN'))

Support

Join our Discord server for help and support.

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

discolytics-2.0.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

discolytics-2.0.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file discolytics-2.0.0.tar.gz.

File metadata

  • Download URL: discolytics-2.0.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for discolytics-2.0.0.tar.gz
Algorithm Hash digest
SHA256 baa5f490e514c543360b504d26fe12d286d4b4cfa7d40362879f77a6bd0c5409
MD5 f1bff249b35868491443baae3622551e
BLAKE2b-256 01f79a4559c1a560b2ea3cd2659384ed3071d2b29d2ef9b9bca3c9cf113f5a49

See more details on using hashes here.

File details

Details for the file discolytics-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: discolytics-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for discolytics-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dfcb453bac836b9ab71a6103b81bf2d8fc1191c5e307b95ccb2f7710f0fda425
MD5 ef4fe1aac52be770b21cb954175a518c
BLAKE2b-256 b8e5325bba8fb7302f14184667283751d17fe98b6bc4c51d06bcb4f0573ad910

See more details on using hashes here.

Supported by

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