Skip to main content

Discord Interaction Application framework for Python

Project description

Discord Interaction Application framework for Python

Tests Pypi

In early development.

The specification and documentation may change without notification.

Any new ideas are welcomed.

A Flask based Discord Application framework.

System Requirements

Install from PyPI

Install and update using pip:

 $ pip install discord-app

Known Limitation

  • After command specification updated (including new command), Discord clients may require up to an hour to update its command list.

Sample Server Application

#!/usr/bin/env python3
# app.py
import discord_app

from . import app_config

PORT = "8080"

app = discord_app.Application.from_basic_data(
    id=app_config.APPLICATION_ID,
    public_key=app_config.PUBLIC_KEY,
    bot_token=app_config.BOT_TOKEN,
    # Set Discord interaction endpoint URL to http(s)://<YOUR-ADDRESS>:<PORT>/<ENDPOINT>
    endpoint="/api/discord/command"
)

app._flask.testing = True
app._logger.setLevel(logging.DEBUG)


@app.application_command(
    options=discord_app.ApplicationCommand(
        name="version",
        name_localizations={
            "zh-TW": "顯示程式版本"
        },
        type=discord_app.ApplicationCommandType.CHAT_INPUT,
        description="Show application version",
        description_localizations={
            "zh-TW": "顯示程式版本"
        }
    ),
    register_on_change=True  # Register command on specification change or is new command.
)
def show_version(_: discord_app.InteractionRequest) -> discord_app.InteractionResponse:
    return discord_app.InteractionResponse(
        type=discord_app.InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
        data=discord_app.InteractionResponseMessage(
            content="test application/0.0.1"
        )
    )

app.run(
    host="0.0.0.0",
    port=PORT
)
 $ python3 app.py

Links

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

discord_app-0.0.1a1.tar.gz (21.2 kB view hashes)

Uploaded Source

Built Distribution

discord_app-0.0.1a1-py3-none-any.whl (25.3 kB view hashes)

Uploaded Python 3

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