interactions.py
interactions.py copied to clipboard
feat: add support for user-installable apps
Pull Request Type
- [x] Feature addition
- [x] Bugfix (PR would not work without them)
- [x] Documentation update
- [ ] Code refactor
- [ ] Tests improvement
- [ ] CI/CD pipeline enhancement
- [ ] Other: [Replace with a description]
Description
This PR adds support for user-installable applications, allowing developers to let users install the bot to themselves to use as they wish. This also adds many fields related to user-installable applications and fixes a few bugs out of necessity.
Changes
The scope of this PR is quite large, even with ta set scope in mind. That being said, here's a summary:
- Add
contextsandintegration_typestoInteractionCommandand its related decorators.dm_permissionhas been depreciated and is no longer serialized - instead, it is converted to itscontextsequivalent.- Hybrid commands also support these two fields, though for prefixed commands, it only attempts to mock
contexts.
- Add
@contextsand@integration_typesdecorators to make specifying them easy.- This PR also adds two sections (replacing the old
dm_permissionsection) to explain these two.
- This PR also adds two sections (replacing the old
- Add
authorizing_integration_ownersandcontexttoBaseInteractionContext. - Add
interaction_metadatatoMessageand note deprecation ofinteractionfield. - Add
integration_types_configtoApplication, although this is extremely basic. - Added other related fields and enums.
Possible things to consider:
- Should
@contextsbe renamed to something else for clarity? - Should there be something like
disable_dm_commandsbe added toClientfor the newcontextsandintegration_types?
Related Issues
#1634
Test Scenarios
from interactions import contexts
@slash_command(name="my_guild_only_command")
@contexts(guild=True, bot_dm=False, private_channel=False)
async def my_command_function(ctx: SlashContext):
...
from interactions import integration_types
@slash_command(name="my_command")
@integration_types(guild=True, user=True)
async def my_command_function(ctx: SlashContext):
...
Python Compatibility
- [ ] I've ensured my code works on Python
3.10.x - [x] I've ensured my code works on Python
3.11.x
Checklist
- [x] I've run the
pre-commitcode linter over all edited files - [x] I've tested my changes on supported Python versions
- [ ] I've added tests for my code, if applicable
- [x] I've updated / added documentation, where applicable
New error I'm getting as of today when responding to application commands
Doesn't happen on unstable, only userapps.
The command is responded to fine, but placing the item into the cache appears to be the problem.
Traceback (most recent call last):
File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\client\client.py", line 1917, in __dispatch_interaction
response = await callback
^^^^^^^^^^^^^^
File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\client\client.py", line 1785, in _run_slash_command
return await command(ctx, **ctx.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\models\internal\command.py", line 132, in __call__
await self.call_callback(self.callback, context)
File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\models\internal\application_commands.py", line 841, in call_callback
return await self.call_with_binding(callback, ctx)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\models\internal\callback.py", line 44, in call_with_binding
return await callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Scratch\Documents\Git\June\bot-test.py", line 21, in idacUpdateRoles
await ctx.send("update command issued", ephemeral=True)
File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\models\internal\context.py", line 565, in send
return await super().send(
^^^^^^^^^^^^^^^^^^^
File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\client\mixins\send.py", line 123, in send
message = self.client.cache.place_message_data(message_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\client\smart_cache.py", line 436, in place_message_data
message = Message.from_dict(data, self._client)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\models\discord\base.py", line 36, in from_dict
data = cls._process_dict(data, client)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\models\discord\message.py", line 559, in _process_dict
data["interaction_metadata"] = MessageInteractionMetadata.from_dict(data["interaction_metadata"], client)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\models\discord\base.py", line 37, in from_dict
return cls(client=client, **cls._filter_kwargs(data, cls._get_init_keys()))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: MessageInteractionMetadata.__init__() missing 1 required keyword-only argument: 'user_id'
They changed the payload recently, yes. I'll fix it soon.
This PR, as well as the branch, has been rebased. The bug mentioned above should also be fixed.
Another rebase has been done to match the branch closely with 5.12.0. It's unlikely that I'll do any more rebases.