Skip to main content

Getting started

Installation#

Prerequisite: Install Python 3.8+ on your local environment.

Use the package manager pip to install dispair.

pip install dispair

QuickStart#

from dispair import Router
from dispair import WebhookClient
router = Router()
@router.interaction(name="8ball", description="Let the 8ball take the wheel")
async def _8ball(inter: Interaction):
answer = random.choice(["Yes", "No", "Maybe"])
return f"> {answer}"
def main() -> None:
if os.getenv("ENVIRONMENT") is None:
load_dotenv(dotenv_path='.env')
client = WebhookClient(
os.getenv("BOT_TOKEN"),
os.getenv("APP_ID"),
os.getenv("APP_PUBLIC_KEY"),
)
client.attach_router(router)
client.run()
if __name__ == "__main__":
main()

In this quickstart example, we:

  • Create a dispair.Router and create an interaction route
  • Define a dispair.WebhookClient and pass in our necessary environment variables: our discord BOT_TOKEN, our discord APP_ID, and our discord APP_PUBLIC_KEY, all of which we can find at the Discord Developer Portal
  • Run our client