Useful tools for using the Discord Interactions API
Project description
discord-interactions-python
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.
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
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 discord-interactions-0.4.0.tar.gz.
File metadata
- Download URL: discord-interactions-0.4.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/2.7.18 Darwin/20.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41bd0289a6460437c7382ec56d99ee604e8cb15259f2d831ae1d248709f8bcb2
|
|
| MD5 |
7798a0ada3455a7d1f5b4148691f9fa8
|
|
| BLAKE2b-256 |
9f610fb857ffcbc9a0a946caf0a50874f80ba98798ca583ba59f7f34e22912c0
|
File details
Details for the file discord_interactions-0.4.0-py3-none-any.whl.
File metadata
- Download URL: discord_interactions-0.4.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/2.7.18 Darwin/20.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc8dcac17873a5bf0b065967b109fabf626a02fe21226369a13e1ee2a6bcd833
|
|
| MD5 |
881e7f982b85e14ba9eb685facbd5f70
|
|
| BLAKE2b-256 |
deef21bb4be7e589c038bd0d73b6be53e045daaf785b4cbb6c6db3dabab810ad
|