A Python Discord Interaction bot API wrapper.
Project description
httpcord
A Python Discord Interaction bot API wrapper.
pip install --update httpcord
From examples/*.py
import random
from httpcord import HTTPBot, CommandResponse, Interaction
from httpcord.embed import Embed
from httpcord.enums import InteractionResponseType
from httpcord.types import AutocompleteChoice
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.command("embed")
async def embed(interaction: Interaction) -> CommandResponse:
embed = Embed(title="Embed title")
embed.add_field(name="Embed field title 1", value="Embed field value 1", inline=False)
embed.add_field(name="Embed field title 2", value="Embed field value 2", inline=False)
embed.add_field(name="Embed field title 3", value="Embed field value 3", inline=True)
embed.add_field(name="Embed field title 4", value="Embed field value 4", inline=True)
return CommandResponse(
type=InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
embeds=[embed],
)
async def string_autocomplete(interaction: Interaction, current: str) -> list[AutocompleteChoice]:
return [AutocompleteChoice(name=f"this is an autocomplete: {current}", value=current)]
@bot.command(
name="autocomplete",
description="command with autocomplete",
autocompletes={
"string": string_autocomplete,
},
)
async def autocomplete_command(interaction: Interaction, *, string: str) -> CommandResponse:
return CommandResponse(
type=InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
embeds=[Embed(title=string)],
)
bot.start(CLIENT_TOKEN)
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
httpcord-0.0.5.tar.gz
(7.9 kB
view details)
Built Distribution
httpcord-0.0.5-py3-none-any.whl
(16.4 kB
view details)
File details
Details for the file httpcord-0.0.5.tar.gz
.
File metadata
- Download URL: httpcord-0.0.5.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9875776dd2deb7260454309bc7676b3d17a92eb03689e10566e4e2f34ca9f0e2 |
|
MD5 | 86df9bc302903c2c41cefb42e596b6d8 |
|
BLAKE2b-256 | 09b45f489b0481d8547b01f5091e1c4e98c83e6c2910c2ceb70fe303ef19e470 |
File details
Details for the file httpcord-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: httpcord-0.0.5-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e5f5c641ae59327d5c6bc74059e5e4fbbcb57461d68aa219a6bc7449860c467 |
|
MD5 | 8b4f79660938f9ea62f07962199b8892 |
|
BLAKE2b-256 | 02637d586b742925a6515d86d2c9bea1fb580dbde63bd27741ea00c8825941be |