Skip to main content

A powerful asynchronous library for creating Discord bots in Python.

Project description

Hata

A blazing fast Discord API wrapper that you can't deny

Support Guild | Topical documentation | Examples | Technical documentation | Source


New hata versions use Discord API V10 .

About

Hata is an asynchronous Discord API wrapper built on top of scarletio. It is designed to be easy to use, with also providing rich API offering everything what an advanced developer might need.

Named after Hata no Kokoro from Touhou Project.

Why hata?

  • Multiple simultaneous clients

    Hata can run multiple clients from the same instance without sacrificing performance.

  • Performant

    Fast concurrent code based on async/await paradigm with cache control, PyPy support and much more!

  • Newest API features

    Whatever Discord decides to release/update/break Hata will support it natively in no time!

  • 100% Python

    Built in Python! Easy to code, easy to read, easy to maintain.

Usage

The following example answers on ping message.

from hata import Client, wait_for_interruption

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()

wait_for_interruption()

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

from hata import Client, wait_for_interruption

Saki = Client('TOKEN', extensions='commands_v2', prefix='s!')

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

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

Saki.start()

wait_for_interruption()

Or use slash commands!

from hata import Client, Guild, wait_for_interruption

GUILD = Guild.precreate(guild_id)

Seija = Client('TOKEN', extensions='slash')

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

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

Seija.start()

wait_for_interruption()

Note: You need to restart your client, or the slash command wont show up. If there are more than 50 integrations (bots) in a guild, some of the (integrations) bots wont be able to use slash commands. This is currently a Discord limitation.

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.

Sometimes leaving the main thread might cause problems when trying to shut down the bot(s). At this case, you might want to use wait_for_interruption(), which disconnects the clients gracefully and closes the event loop on keyboard interrupt.

Installation

To install Hata simply do

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

# Windows
$ python -m pip install hata

# Voice Support
$ python -m pip install hata[voice]

And you are good to go! Hata has native pypy support as well if you need some more speed!

Dependencies

Requirements

Optional

Get in touch

If you have issues, suggestions, want to contribute, or just want to hang out, join our discord server.

Invite

Acknowledgements

Shout-Out to our brave testers, who are helping the most to improve Hata!

  • Nekosia [Grammar]
  • Proxisha [Feature requests & Bug hunting]
  • Hime Esuto [Bug hunting]
  • BrainDead [Documentation improvements]
  • Zeref [Features & Typos & Bug hunting]
  • vinam [Bug hunting[asyncio extension]]

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.2.15.tar.gz (909.6 kB view hashes)

Uploaded Source

Built Distribution

hata-1.2.15-py3-none-any.whl (1.5 MB view hashes)

Uploaded Python 3

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