Skip to main content

A low level Discord API wrapper

Project description

Nextcore

A low level Discord API wrapper.

✨ Features

  • Speed

    We try to make the library as fast as possible, without compromising on readability of the code or features.

  • Modularity

    All the components can easily be swapped out with your own.

  • Control

    Nextcore offers fine-grained control over things most libraries don't support.

    This currently includes:

    • Setting priority for individual requests
    • Swapping out components

Examples

🏓 Ping pong

A simple "ping pong" example in nextcore. This will respond with "pong" each time someone sends "ping" in the chat.

import asyncio
from os import environ
from typing import cast

from discord_typings import MessageData

from nextcore.gateway import ShardManager
from nextcore.http import BotAuthentication, HTTPClient, Route

# Constants
AUTHENTICATION = BotAuthentication(environ["TOKEN"])

# Intents are a way to select what intents Discord should send to you.
# For a list of intents see https://discord.dev/topics/gateway#gateway-intents
GUILD_MESSAGES_INTENT = 1 << 9
MESSAGE_CONTENT_INTENT = 1 << 15

INTENTS = GUILD_MESSAGES_INTENT | MESSAGE_CONTENT_INTENT  # Guild messages and message content intents.


# Create a HTTPClient and a ShardManager.
# A ShardManager is just a neat wrapper around Shard objects.
http_client = HTTPClient()
shard_manager = ShardManager(AUTHENTICATION, INTENTS, http_client)


@shard_manager.event_dispatcher.listen("MESSAGE_CREATE")
async def on_message(message: MessageData):
    # This function will be called every time a message is sent.
    if message["content"] == "ping":
        # Send a pong message to respond.
        route = Route("POST", "/channels/{channel_id}/messages", channel_id=message["channel_id"])

        await http_client.request(
            route,
            rate_limit_key=AUTHENTICATION.rate_limit_key,
            json={"content": "pong"},
            headers=AUTHENTICATION.headers,
        )


async def main():
    await http_client.setup()

    # This should return once all shards have started to connect.
    # This does not mean they are connected.
    await shard_manager.connect()

    # Raise a error and exit whenever a critical error occurs
    (error,) = await shard_manager.dispatcher.wait_for(lambda: True, "critical")

    raise cast(Exception, error)


asyncio.run(main())

More examples can be seen in the examples directory.


Contributing

Want to help us out? Please read our contributing docs.

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

nextcore-2.0.2.tar.gz (37.3 kB view details)

Uploaded Source

Built Distribution

nextcore-2.0.2-py3-none-any.whl (74.2 kB view details)

Uploaded Python 3

File details

Details for the file nextcore-2.0.2.tar.gz.

File metadata

  • Download URL: nextcore-2.0.2.tar.gz
  • Upload date:
  • Size: 37.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for nextcore-2.0.2.tar.gz
Algorithm Hash digest
SHA256 5093dd38044e8dd6573f9297e6db60978fe9a895ee4f23803e62a5f672eda31a
MD5 e311340e22a405cee760df819eeb7ce1
BLAKE2b-256 98b99be4aba59b3583df7eeaa18150e4887d7ebbc7d92d383cc5ad9ab8084c0c

See more details on using hashes here.

File details

Details for the file nextcore-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: nextcore-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 74.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for nextcore-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8d6085853c6f6040c69243e0b74a5ec79f68b77a7e9ac242b77b5163abddbbd2
MD5 28356f89af81d2bde2d2d0841bd918c5
BLAKE2b-256 d966eb14319dac1695fa8dedd4777606998ac35742057026bca52800c420cf7e

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