Skip to main content

A Python Discord Interaction bot API wrapper.

Project description

httpcord

A Python Discord Interaction bot API wrapper.

pip install --update httpcord

From examples/hello-world.py

import random

from httpcord import HTTPBot, CommandResponse, Interaction
from httpcord.enums import InteractionResponseType

CLIENT_ID = 0000000000000000000000
CLIENT_PUBLIC_KEY = "..."
CLIENT_TOKEN = "..."

bot = HTTPBot(
    client_id=CLIENT_ID,
    client_public_key=CLIENT_PUBLIC_KEY,
    register_commands_on_startup=True,
)

@bot.command("hello-world")
async def hello_world(interaction: Interaction) -> CommandResponse:
    return CommandResponse(
        type=InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
        content=f"hello, {interaction.user.mention}! You joined this server at <t:{int(interaction.user.joined_at.timestamp())}:F>.",
    )

@bot.command("guess-number")
async def guess_number(interaction: Interaction, *, guess: int, max_value: int = 10) -> CommandResponse:
    winning_number = random.randint(0, max_value)
    if guess == winning_number:
        return CommandResponse(
            type=InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
            content="Yay! You guessed the number correctly :)",
        )
    return CommandResponse(
        type=InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
        content="Aww, you got the number wrong. Better luck next time :)",
    )

bot.start(CLIENT_TOKEN)

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

httpcord-0.0.4.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

httpcord-0.0.4-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file httpcord-0.0.4.tar.gz.

File metadata

  • Download URL: httpcord-0.0.4.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for httpcord-0.0.4.tar.gz
Algorithm Hash digest
SHA256 553d2d5ced7442c8a47447d8803acb1bb5eb64ad67766da638e7648f135cbf5b
MD5 03361eb3a5494dcb0d50bc3dd9a80549
BLAKE2b-256 ba7a895124b50243277fd8e649d14684918bfdcede51f67d7411308eb6aa6108

See more details on using hashes here.

File details

Details for the file httpcord-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: httpcord-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for httpcord-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 08ecf88169dc5bffb795f00fe62ec1b07dce076e30d6a143657c5ce56a891718
MD5 6f893b273159ef43f68e155502fe1b6f
BLAKE2b-256 b34284298ad3417d71dfc4e02d93c432bfd8da661e0195a0c2fcd6b37ba02304

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