The discolytics python package can be used in any python codebase. The below example uses discord.py.
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 discordimport osfrom dotenv import load_dotenvfrom discolytics import Discolyticsfrom time import sleepimport jsonload_dotenv()# initiate Discolytics clientdiscolytics =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.eventasyncdefon_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 endsend_command()# send events to Discolytics@client.eventasyncdefon_socket_raw_receive(raw_msg):ifnotisinstance(raw_msg, str):return msg = json.loads(raw_msg) event_type = msg.get("t") data = msg.get("d")ifnot data ornot event_type:return guild_id = data.pop('guild_id', None) discolytics.send_event(name=event_type, guild_id=guild_id)# send interactions to discolyticsif event_type =='INTERACTION_CREATE':type= data.pop('type', None)ifnottype:return discolytics.post_interaction(type=type, guild_id=guild_id)client.run(os.getenv('TOKEN'))