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.3.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

httpcord-0.0.3-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: httpcord-0.0.3.tar.gz
  • Upload date:
  • Size: 6.5 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.3.tar.gz
Algorithm Hash digest
SHA256 21428ab1eee4a8a2aa1f6543b6fc3e7ce3073cb87728611b9d1a4d6df5b4b3c8
MD5 74050641e19773285192fb9e5f7b3936
BLAKE2b-256 47ceddad4b90ce20dc30699888cd00173e7672c172152666fde1cb6b62b7b1f3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: httpcord-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 14.6 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9ed10f4df147201d35c7f257e73458e20a6119fcf3f4f6ea6845e53b2d220f20
MD5 a54cec3dc84d7cfcf5d11df5f4d07eb3
BLAKE2b-256 818732baaaba453546900e25c9e906afbfc05edd2ede6a00bdca8f45c847c101

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