Python SDK for building Tavern bots
Project description
taverns.py
Python SDK for building Tavern bots on the Taverns platform.
Installation
pip install taverns.py
# or from source:
pip install -e .
Requires Python 3.10+.
Quick Start
import os
from taverns import Client, Intents
client = Client(intents=Intents.MESSAGES | Intents.MESSAGE_CONTENT)
@client.event
async def on_ready():
print(f"Logged in as {client.user.display_name}")
@client.event
async def on_message_create(message):
if message.sender_id == client.user.id:
return
if message.content == "!ping":
await client.send_message(message.tavern_id, message.channel_id, content="Pong!")
client.run(os.environ["BOT_TOKEN"])
Slash Commands
from taverns import Client, Intents, Interaction
from taverns.commands import command, option
from taverns.types import CommandOptionType
client = Client(intents=Intents.MESSAGES | Intents.INTERACTIONS)
@client.event
async def on_ready():
await client.register_commands([
command("ping", "Check latency"),
command("greet", "Greet someone", options=[
option("name", "Who to greet", CommandOptionType.STRING, required=True),
]),
])
@client.event
async def on_interaction_create(interaction: Interaction):
if interaction.command_name == "ping":
await interaction.reply("Pong!")
elif interaction.command_name == "greet":
name = interaction.get_option("name", "World")
await interaction.reply(f"Hello, {name}!")
client.run(os.environ["BOT_TOKEN"])
Deferred Responses
@client.event
async def on_interaction_create(interaction: Interaction):
if interaction.command_name == "slow":
await interaction.defer_reply() # Shows "thinking..." to the user
result = await do_slow_work()
await interaction.follow_up(f"Done: {result}")
Ephemeral Responses
await interaction.reply("Only you can see this", ephemeral=True)
Webhook Verification
from taverns import verify_webhook_signature
is_valid = verify_webhook_signature(
raw_body=request.data,
signature=request.headers["X-Tavern-Signature"],
secret=WEBHOOK_SECRET,
timestamp=request.headers.get("X-Tavern-Timestamp"),
)
Intents
Control which events your bot receives:
from taverns import Intents
# Specific intents
client = Client(intents=Intents.MESSAGES | Intents.INTERACTIONS)
# All non-privileged intents
client = Client(intents=Intents.DEFAULT)
# All intents (including privileged)
client = Client(intents=Intents.ALL)
Privileged intents (MESSAGE_CONTENT, MEMBERS) are self-serve for private bots.
REST Client
For direct API access:
# Available after login
channels = await client.rest.get_channels(tavern_id)
members = await client.rest.get_members(tavern_id)
messages = await client.rest.get_messages(tavern_id, channel_id, limit=50)
Links
- PyPI package
- API Documentation
- Developer Portal
- taverns.js (Node.js SDK)
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
taverns_py-0.1.1.tar.gz
(18.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file taverns_py-0.1.1.tar.gz.
File metadata
- Download URL: taverns_py-0.1.1.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b852ee01f24be14103c051e7579f5fc857ee28b29e16213576342dabe93a113
|
|
| MD5 |
4ab31adac83e8ebdc004d0b3c60be475
|
|
| BLAKE2b-256 |
885b07b6928c38516aeabc3cd35075a048efc53f8837fb0164d793949f9088bf
|
File details
Details for the file taverns_py-0.1.1-py3-none-any.whl.
File metadata
- Download URL: taverns_py-0.1.1-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
602898f9c1c920e36b03d7428386309fa17c6d7d6463e5f7a17f253c478be162
|
|
| MD5 |
8a002caa864de20ac22b561838866a63
|
|
| BLAKE2b-256 |
abdc3a5fc6215624c57e0f689e8aa6d928fc33fcc8dadecb3d5cc09d9d82716b
|