-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create transformers.py for app command transformers
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""This file is a part of the source code for snakecore. | ||
This project has been licensed under the MIT license. | ||
Copyright (c) 2024-present pygame-community. | ||
This file defines some transformers for application command argument parsing. | ||
""" | ||
|
||
import discord | ||
from discord import app_commands | ||
from discord.ext import commands | ||
|
||
_DECBotT = commands.Bot | commands.AutoShardedBot | ||
|
||
|
||
class MessageTransformer(app_commands.Transformer): | ||
"Transforms to a :class:`discord.Message`." | ||
|
||
async def transform( | ||
self, interaction: discord.Interaction[_DECBotT], value: str | ||
) -> discord.Message: | ||
try: | ||
return await commands.MessageConverter().convert( | ||
await commands.Context.from_interaction(interaction), value | ||
) | ||
except commands.BadArgument: | ||
raise app_commands.TransformerError( | ||
value, discord.AppCommandOptionType.string, self | ||
) | ||
|
||
|
||
Message = app_commands.Transform[discord.Message, MessageTransformer] | ||
"Transforms to a :class:`discord.Message`." | ||
|
||
__all__ = ("MessageTransformer", "Message") |