Skip to main content

discord-interactions-python

PyPI - License PyPI - Python Version

Types and helper functions for Discord Interactions webhooks.

Installation

Available via pypi:

pip install discord-interactions

Usage

Use the InteractionType and InteractionResponseType enums to process and respond to webhooks.

Use verify_key to check a request signature:

if verify_key(request.data, signature, timestamp, 'my_client_public_key'):
    print('Signature is valid')
else:
    print('Signature is invalid')

Use verify_key_decorator to protect routes in a Flask app:

import os

from flask import Flask, request, jsonify

from discord_interactions import verify_key_decorator, InteractionType, InteractionResponseType

CLIENT_PUBLIC_KEY = os.getenv('CLIENT_PUBLIC_KEY')

app = Flask(__name__)

@app.route('/interactions', methods=['POST'])
@verify_key_decorator(CLIENT_PUBLIC_KEY)
def interactions():
  if request.json['type'] == InteractionType.APPLICATION_COMMAND:
    return jsonify({
        'type': InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
        'data': {
            'content': 'Hello world'
        }
    })

Exports

This module exports the following:

InteractionType

An enum of interaction types that can be POSTed to your webhook endpoint.

InteractionResponseType

An enum of response types you may provide in reply to Discord's webhook.

InteractionResponseFlags

An enum of flags you can set on your response data.

verify_key(raw_body: str, signature: str, timestamp: str, client_public_key: str) -> bool:

Verify a signed payload POSTed to your webhook endpoint.

verify_key_decorator(client_public_key: str)

Flask decorator that will verify request signatures and handle PING/PONG requests.

Release files for discord-interactions 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for discord-interactions 0.4.0
File Size Uploaded
discord-interactions-0.4.0.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for discord-interactions 0.4.0
File Interpreter ABI Platform
discord_interactions-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.2 kB

Release files / discord-interactions-0.4.0.tar.gz

Download URL discord-interactions-0.4.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
41bd0289a6460437c7382ec56d99ee604e8cb15259f2d831ae1d248709f8bcb2
BLAKE2b-256 checksum
How to use checksums
9f610fb857ffcbc9a0a946caf0a50874f80ba98798ca583ba59f7f34e22912c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/2.7.18 Darwin/20.6.0

Release files / discord_interactions-0.4.0-py3-none-any.whl

Download URL discord_interactions-0.4.0-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc8dcac17873a5bf0b065967b109fabf626a02fe21226369a13e1ee2a6bcd833
BLAKE2b-256 checksum
How to use checksums
deef21bb4be7e589c038bd0d73b6be53e045daaf785b4cbb6c6db3dabab810ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/2.7.18 Darwin/20.6.0

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page