pycord icon indicating copy to clipboard operation
pycord copied to clipboard

feat: user-installable apps

Open plun1331 opened this issue 2 years ago • 36 comments

Installation & Testing

If you're looking to try this out, use the following:

pip install git+https://github.com/Pycord-Development/pycord@feat/ua

Note that this is still a preview from Discord, and things may be subject to change.


Summary

https://discord.com/developers/docs/change-log#userinstallable-apps-preview

Information

  • [ ] This PR fixes an issue.
  • [x] This PR adds something new (e.g. new method or parameters).
  • [ ] This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • [ ] This PR is not a code change (e.g. documentation, README, typehinting, examples, ...).

Checklist

  • [x] I have searched the open pull requests for duplicates.
  • [x] If code changes were made then they have been tested.
    • [x] I have updated the documentation to reflect the changes.
  • [ ] If type: ignore comments were used, a comment is also left explaining why.
  • [x] I have updated the changelog to include these changes.

plun1331 avatar Mar 23 '24 14:03 plun1331

tested on production nothing broke greatest feeling ever

plun1331 avatar Mar 24 '24 05:03 plun1331

Was just thinking about this, but some bots have a lot of commands and it might be hard to change all of them to support this This could be solved by wrapping the command decorators, however, that's rather inconvenient

My idea is I add 2 parameters to Bot that act as defaults for contexts and integration_types, similar to debug_guilds, possibly named default_command_contexts and default_command_integration_types respectively Lmk your thoughts and if nobody opposes I'll implement it later tomorrow

plun1331 avatar Mar 24 '24 05:03 plun1331

that wasn't supposed to happen

plun1331 avatar Mar 24 '24 20:03 plun1331

We should also make a guide for it maybe

Lulalaby avatar Mar 25 '24 22:03 Lulalaby

We should also make a guide for it maybe

not my problem :)

plun1331 avatar Mar 26 '24 04:03 plun1331

I've been testing this PR out today, and all's good except for this weird issue. I use custom emojis for almost all of my commands and everything's fine when using them normally in a guild the bot is in. However, if I'm using the user-installed app part of it, some commands don't show the emoji at all. I've got 0 idea why this is happening or how to exactly replicate it.

AlexTheGoat69 avatar Apr 05 '24 20:04 AlexTheGoat69

I've been testing this PR out today, and all's good except for this weird issue. I use custom emojis for almost all of my commands and everything's fine when using them normally in a guild the bot is in. However, if I'm using the user-installed app part of it, some commands don't show the emoji at all. I've got 0 idea why this is happening or how to exactly replicate it.

@Lulalaby ?

JustaSqu1d avatar Apr 05 '24 20:04 JustaSqu1d

I've been testing this PR out today, and all's good except for this weird issue. I use custom emojis for almost all of my commands and everything's fine when using them normally in a guild the bot is in. However, if I'm using the user-installed app part of it, some commands don't show the emoji at all. I've got 0 idea why this is happening or how to exactly replicate it.

I'd expect that to be a Discord issue, this pr shouldn't mess with emojis at all

plun1331 avatar Apr 05 '24 20:04 plun1331

@Vondyy @plun1331 @JustaSqu1d This is a purpose-discord-limitation "Use External Emojis" is not allowed discord-wide for user app commands. Mainly because of the nitro gate for users. I can't give you more details about it tho, since it's not public

Lulalaby avatar Apr 06 '24 05:04 Lulalaby

Makes sense other than the fact that 99 percent of my user app commands are using custom emojis fine. When no one is in the custom emoji server. So it's not like all of them isn't working, which is confusing.

AlexTheGoat69 avatar Apr 06 '24 09:04 AlexTheGoat69

Marking this as a draft until Discord takes this out of preview (soon™️)

plun1331 avatar Apr 16 '24 18:04 plun1331

This will still take a while, since the PO is currently ill

Lulalaby avatar Apr 16 '24 18:04 Lulalaby

This will still take a while, since the PO is currently ill

hope they get well soon™️

plun1331 avatar Apr 16 '24 18:04 plun1331

~~ref. https://discord.com/channels/881207955029110855/881735314987708456/1231382350324301906~~ fixed with 4f56ea5

plun1331 avatar Apr 20 '24 23:04 plun1331

I have been working with this PR and when working with message commands the channel is not being set properly. I also tested on master and did not get this issue so I believe it is in the PR.

No matter if the message command is used in a guild or a DM the channel is always set to the DM channel between the bot and my user. This also leads to the guild being set to None. I confirmed via debug logging that Discord is sending the correct information.

I am willing to test any changes.

Icebluewolf avatar Apr 23 '24 22:04 Icebluewolf

I have been working with this PR and when working with message commands the channel is not being set properly. I also tested on master and did not get this issue so I believe it is in the PR.

No matter if the message command is used in a guild or a DM the channel is always set to the DM channel between the bot and my user. This also leads to the guild being set to None. I confirmed via debug logging that Discord is sending the correct information.

I am willing to test any changes.

If you'd like to contribute you can make a PR, just target the feat/ua branch

plun1331 avatar Apr 24 '24 00:04 plun1331

The problem is I looked at the code for about an hour and could not figure out what is causing the bug 😅

Icebluewolf avatar Apr 24 '24 01:04 Icebluewolf

classic

Lulalaby avatar Apr 24 '24 01:04 Lulalaby

No matter if the message command is used in a guild or a DM the channel is always set to the DM channel between the bot and my user. This also leads to the guild being set to None.

This is a pretty weird bug, as this PR makes no changes to how channel/guild is being set when interactions are received Can you double check that this isn't occurring on master as well?

plun1331 avatar Apr 24 '24 03:04 plun1331

I have checked again and it appears to work on master but not on this PR. I checked the difference between the interaction payload that I received The only differences were

  • The addition of d.context (value 0)
  • The addition of d.authorizing_integration_owners (value {1: my_user_id})
  • A change in app permissions as I used 2 different bots, but this should have no effect

Icebluewolf avatar Apr 24 '24 12:04 Icebluewolf

@Icebluewolf does it only affect context menu commands of the type message?

Lulalaby avatar Apr 24 '24 14:04 Lulalaby

I am not entirely sure what you mean as User Apps cannot fetch messages as far as I am aware. When running

m = await ctx.respond(embed=await view.create_embed(), view=view)
m = await m.original_response()

The correct channel and guild are set. I am not sure of any other ways to obtain a message within the context of a user app.

Icebluewolf avatar Apr 24 '24 22:04 Icebluewolf

I'm asking where the problem occurs. In which type of interaction.

"No matter if the message command is used in a guild or a DM the channel is always set to the DM channel between the bot and my user. This also leads to the guild being set to None."

Lulalaby avatar Apr 24 '24 22:04 Lulalaby

The wrong channel is set on the message returned from only message commands from my testing. It is wrong when the message command is used in a guild or a DM with another user. However discord.ApplicationContext.channel is correctly set within a message command.

Icebluewolf avatar Apr 24 '24 22:04 Icebluewolf

It looks like the problem is here: https://github.com/Pycord-Development/pycord/blob/830c7a0e8285c6d0849c5288ef19dc1dafb059d2/discord/commands/core.py#L1853-L1866 if the channel is not cached, the library creates a DM channel and adds it to cache (not ideal) I will probably change this to be a PartialMessageable, as defaulting to a DM channel doesn't make sense (at least not anymore)

plun1331 avatar Apr 24 '24 22:04 plun1331

Uh.. Y'all are aware that discord sends the whole channel object in the interaction..?

Lulalaby avatar Apr 24 '24 23:04 Lulalaby

Unless im mistaken.

Lulalaby avatar Apr 24 '24 23:04 Lulalaby

They do. d.channel has a complete channel object. At least for message command interactions.

Icebluewolf avatar Apr 24 '24 23:04 Icebluewolf

Then let's just construct from that instead of relaying on cache

Lulalaby avatar Apr 24 '24 23:04 Lulalaby

That's very odd, because I already implemented Interaction.channel last year in #2025... if I had to guess, I neglected to update invoke to support this

NeloBlivion avatar Apr 25 '24 00:04 NeloBlivion