Skip to main content

Easy to use API wrapper for DiscordBotList in Python

Project description

discordbotlist.py

Easy to use API wrapper for DiscordBotList in Python

Installation

[!WARNING] You need to install an optional package either discordbotlist-py[pycord] or discordbotlist-py[discord]

# For discord.py
pip install discordbotlist-py[discord]

# For py-cord
pip install discordbotlist-py[pycord]

Usage

discord.py usage

import discord
from discordbotlist import DblClient
from discord import Intents, Client
from discord import app_commands

class MyClient(Client):
    def __init__(self, *, intents: Intents):
        super().__init__(intents=intents)
        self.tree = app_commands.CommandTree(self)

    async def setup_hook(self):
        await self.tree.sync()

bot = MyClient(intents=Intents.all())

# Initialize the DBL client with your API token
dbl = DblClient("your_dbl_token_here", bot)

@bot.event
async def on_ready():
    print(f"Logged in as {bot.user}")
    
    # Start auto-posting stats every hour (3600 seconds)
    dbl.start_posting(interval=3600)
    
    # Post commands to DiscordBotList
    commands = await bot.tree.fetch_commands()
    command_list = [
        {
            "name": cmd.name,
            "description": cmd.description,
            "type": cmd.type.value
        }
        for cmd in commands
    ]
    await dbl.post_command(command_list)
    print(f"Posted {len(command_list)} commands to DiscordBotList.")

# Listen for DBL stats updates
@dbl.event
async def on_dbl_updated(payload):
    print(f"DiscordBotList stats updated: {payload}")

# Listen for DBL commands updates
@dbl.event
async def on_dbl_commands_updated(commands):
    print(f"DiscordBotList commands updated: {commands}")

bot.run("your_bot_token_here")

py-cord usage

discord.py usage

import discord
from discordbotlist import DblClient, AppCommandPayload
from discord import Intents, Bot

bot = Bot(intents=Intents.all())

# Initialize the DBL client with your API token
dbl = DblClient("your_dbl_token_here", bot)

@bot.event
async def on_ready():
    print(f"Logged in as {bot.user}")
    
    # Start auto-posting stats every hour (3600 seconds)
    dbl.start_posting(interval=3600)
    
    # Post commands to DiscordBotList
    commands = bot.application_commands
    command_list = [
        AppCommandPayload(
            name=cmd.name, description=cmd.description, type=1
        )
        for cmd in commands
    ]

    await dbl.post_command(command_list)
    print(f"Posted {len(command_list)} commands to DiscordBotList.")

# Listen for DBL stats updates
@dbl.event
async def on_dbl_updated(payload):
    print(f"DiscordBotList stats updated: {payload}")

# Listen for DBL commands updates
@dbl.event
async def on_dbl_commands_updated(commands):
    print(f"DiscordBotList commands updated: {commands}")

bot.run("your_bot_token_here")

Manual Stats Posting

# Manually post stats
await dbl.post_status()

Stop Auto-posting

# Stop the auto-posting loop
await dbl.stop_posting()

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

discordbotlist_py-1.0.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

discordbotlist_py-1.0.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file discordbotlist_py-1.0.0.tar.gz.

File metadata

  • Download URL: discordbotlist_py-1.0.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for discordbotlist_py-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2a4bdd0227e9e81a62bc6f717591be5b2d0037844fd388963fda2a052bfb0e08
MD5 0607507096c1f3ffbf9509ba0d4b6e95
BLAKE2b-256 1ee28145efce9c7ab9b500f46c8b28ab93a5b91cf406fd7b2f5c20208a4422cd

See more details on using hashes here.

File details

Details for the file discordbotlist_py-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: discordbotlist_py-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for discordbotlist_py-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d43d1dc76af3861701c7598fa3d4c5851d239c2d9932b4dd84cd89b6fca249a
MD5 1ddbde17e46576f8355d0e7058e1ccd3
BLAKE2b-256 8c77224e7a6c33a4cd56ec5b727e61e451e8e78d4d0b81d416ccb70ccee8110f

See more details on using hashes here.

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