Skip to main content

A powerful asynchronous library for creating Discord bots in Python.

Project description

Hata

Hata is an async Discord API wrapper written in Python named after Hata no Kokoro.

If naming a Discord API wrapper after a Touhou character is not enough to convince you to try it, it has got some real stuff:

  • Fast and simple asynchronous framework to write concurrent code using async/await syntax, but also great for embedding into a threaded system.
  • Running more clients from the same instance.
  • Shared entity cache between shards and clients.
  • Feature rich API for common use cases.
  • Fast rate limit handling.
  • No member objects associated with guilds. Hata uses guild -> user -> guild relation enabling implementing cross-guild features more easily.
  • Optimized dispatch event parsers depending on intents, client count and on handled events as well.
  • Option to disable user presences or even user caching, although disabling user cache is not recommended.
  • Many builtin extension. Including a slash command one as well.
  • Audio sending and receiving.
  • Can interacting with the Discord API without gateway connection.
  • Switching between api version with environmental variable.

Usage

The following example answers on ping message.

from hata import Client

Nue = Client('TOKEN')

@Nue.events
async def ready(client):
    print(f'{client:f} logged in.')

@Nue.events
async def message_create(client, message):
    if message.author.is_bot:
        return

    if message.content == 'ping':
        await client.message_create(message.channel, 'pong')

Nue.start()

An improved example using the commands extension to handle common use cases.

from hata import Client
from hata.ext.commands import setup_ext_commands

Saki = Client('TOKEN')
setup_ext_commands(Saki, 's!')

@Saki.events
async def ready(client):
    print(f'{client:f} logged in.')

@Saki.commands
async def ping(client, message):
    return 'pong'

Saki.start()

Or use slash commands!

from hata import Client, Guild
from hata.ext.slash import setup_ext_slash

GUILD = Guild.precreate(guild_id)

Seija = Client('TOKEN')
setup_ext_slash(Seija)

@Seija.events
async def ready(client):
    print(f'{client:f} logged in.')

@Seija.interactions(guild=GUILD)
async def ping(client, event):
    """ping-pong"""
    return 'pong'

Seija.start()

Note: You need to restart your client, or the slash command wont show up.

If you wonder, how to run up more clients, just put the two code snippet into the same file.

Hata leaves the main thread free, client.start() blocks it only till the client logs in (or fails it), although you can still use the start_clients function, what as it says, starts up all the non-running clients parallelly, so go ahead and start python with -i option, then interact with the clients from your interactive console in runtime.

Installing guide

To install the package use:

# Linux/OS X
$ python3 -m pip install hata

# Windows
$ python -m pip install hata

Hata has native pypy support as well if you need some more speed!

Requirements

Optional requirements

Join our server

If you have issues, suggestions, want to contribute, or just want to send cute neko pictures, join our discord server.

Acknowledgement

Shout-Outs for our brave testers, who are helping the most improving the library:

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

hata-1.1.53.tar.gz (794.5 kB view details)

Uploaded Source

Built Distribution

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

hata-1.1.53-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

Details for the file hata-1.1.53.tar.gz.

File metadata

  • Download URL: hata-1.1.53.tar.gz
  • Upload date:
  • Size: 794.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.2

File hashes

Hashes for hata-1.1.53.tar.gz
Algorithm Hash digest
SHA256 b4bb4a5ab4702537b7175d0222ef5f4027a0df8a1784351b1fcd5c58b7d2a994
MD5 30347580396b28b1a70a597d7bff1844
BLAKE2b-256 14f1edd67936e6e28fb96c0a6cbb5d4d568b3ee4a1aa43bb7dc0b9d58e018cdf

See more details on using hashes here.

File details

Details for the file hata-1.1.53-py3-none-any.whl.

File metadata

  • Download URL: hata-1.1.53-py3-none-any.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.2

File hashes

Hashes for hata-1.1.53-py3-none-any.whl
Algorithm Hash digest
SHA256 c12967144210e8ec053b18f676d10418bce6a837de0c90cd3374937c7ba3c68e
MD5 3efabf0639dc434b67f5ae7a342c7e14
BLAKE2b-256 a2e4b11d4c428333a3523eb0e5aaf78d900a90c929d7a721818380b4ff5db9c2

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