Flask-discord-interactions

Latest version: v2.1.2

Safety actively analyzes 681866 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 6 of 7

0.1.10

This release introduces the ability to use Quart instead of Flask (18, 23). This allows developers to write commands that use asyncio, which is a more familiar experience for longtime discord.py users.

python
from quart import Quart

import quart.flask_patch
from flask_discord_interactions import DiscordInteractions

app = Quart(__name__)
discord = DiscordInteractions(app)

discord.update_slash_commands()

discord.command()
async def ping(ctx):
"Respond with a friendly 'pong'!"
return "Pong!"

Non-async functions still work
discord.command()
def pong(ctx):
return "Ping!"


Additionally, this adds an `AsyncContext` object for handling followup messages:

python
discord.command()
async def wait(ctx, seconds: int):
async def do_followup():
await asyncio.sleep(seconds)
await ctx.edit("Done!")
await ctx.close()

asyncio.create_task(do_followup())
return Response(deferred=True)

Normal followups use the normal Context
discord.command()
def wait_sync(ctx, seconds: int):
def do_followup():
time.sleep(seconds)
ctx.edit("Done!")

threading.Thread(target=do_followup).start()
return Response(deferred=True)


This update also allows embeds to be included in ephemeral responses, as per 19.

0.1.9

New features:
* A `Client` object that can be used to run automated tests against Slash Commands (16)
* An `Embed` dataclass that can be used to create embeds more pythonically (17)

Changes:
* `Context`, `Member`, `Role`, `User`, and `Channel` are now dataclasses, making initialization easier (16)
* `Response` is now a dataclass (17)

Project structure:
* `pytest` is now used to run unit tests and generate coverage reports

0.1.8

This release adds two new options to `app.config`:
- `DONT_VALIDATE_SIGNATURE` disables validating the signature on incoming POST requests
- `DONT_REGISTER_WITH_DISCORD` disables registering slash commands with the Discord API

These can be used to debug a bot locally using Postman, cURL, or a similar tool. Read the documentation [here](https://flask-discord-interactions.readthedocs.io/en/latest/debugging.html) for more information.

Thank you akiller for submitting and documenting this patch! (13)

0.1.7

This release adds the ability to use Python Enums to define option choices using type hinting.

Old syntax (still works, but no longer the recommended way):

python
discord.command(options=[{
"name": "choice",
"description": "Your favorite animal",
"type": CommandOptionType.STRING,
"required": True,
"choices": [
{
"name": "Dog",
"value": "dog"
},
{
"name": "Cat",
"value": "cat"
}
]
}])
def favorite(ctx, choice):
"What is your favorite animal?"
return f"{ctx.author.display_name} chooses {choice}!"


New syntax:

python
class Animal(enum.Enum):
Dog = "dog"
Cat = "cat"

discord.command(annotations={"choice": "Your favorite animal"})
def favorite(ctx, choice: Animal):
"What is your favorite animal?"
return f"{ctx.author.display_name} chooses {choice}!"


Additionally, this version now includes Sphinx docs.

0.1.6

Add a throttle to handle Discord rate-limiting automatically.

Discord lowered the rate-limit for slash command registration. Previously, this library did not respect the rate limit, and it would crash if it received a `429 Too Many Requests` from Discord. This update uses the `X-RateLimit` headers, as per the [Discord docs](https://discord.com/developers/docs/topics/rate-limits), to add a time delay between requests if necessary to avoid this issue.

Thank you to bradday4 for submitting this PR (7)!

0.1.5

This release makes some changes to the syntax for declaring subcommands and command parameters in order to bring it more in line with Discord.py.

Note that the old syntax still works, but moving forward, the new syntax will be the preferred method.

Subcommands

Old syntax:
python
discord.command(options=[
{
"name": "google",
"description": "Search with Google",
"type": CommandOptionType.SUB_COMMAND,
"options": [{
"name": "query",
"description": "Search query",
"type": CommandOptionType.STRING,
"required": True
}]
},
{
"name": "bing",
"description": "Search with Bing",
"type": CommandOptionType.SUB_COMMAND,
"options": [{
"name": "query",
"description": "Search query",
"type": CommandOptionType.STRING,
"required": True
}]
}
])
def search(ctx, subcommand, *, query):
"Search the Internet!"
quoted = urllib.parse.quote_plus(query)
if subcommand == "google":
return f"https://google.com/search?q={quoted}"
if subcommand == "bing":
return f"https://bing.com/search?q={quoted}"


New syntax:
python
comic = discord.command_group("comic")


comic.command()
def xkcd(ctx, number: int):
return f"https://xkcd.com/{number}/"


comic.command()
def homestuck(ctx, number: int):
return f"https://homestuck.com/story/{number}"


Command Parameters

Old syntax:
python
discord.command(options=[{
"name": "channel",
"description": "The channel to show information about",
"type": CommandOptionType.CHANNEL,
"required": True
}])
def channel_info(ctx, channel):
return InteractionResponse("...")


New syntax:
python
discord.command(annotations={"channel": "The channel to show information about"})
def channel_info(ctx, channel: Channel):
return Response(...)


Renaming

Old names are (for now) being kept as aliases.

* `InteractionResponse` -> `Response`
* `InteractionContext` -> `Context`

Page 6 of 7

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.