Skip to content

Conversation

@Kile
Copy link
Contributor

@Kile Kile commented Jan 15, 2022

Summary

I have submitted this pull request before but Danny ended up denying it. I still find this relevant and useful so I am submitting it here again.

This pull request adds the Coro on_check_failure to the View class which is called when interaction_check returns False and defers the interaction, if not previously responded to, per default (EDIT: it now does not defer the interaction per default anymore).

Why this is needed:
interaction_check's purpose is to check if the interaction should go through, not really to handle the case of it not going through. A separate method handling what to do when the check fails seems more clean and useful to deal with that.
So thing code which would previously look like

async def interaction_check(self, interaction: discord.Interaction) -> bool:
    if not some_check():
        await interaction.response.defer()
        return False
    return True

looks now like

async def on_check_failure(self, interaction: discord.Interaction) -> None:
    await interaction.response.defer()

async def interaction_check(self, interaction: discord.Interaction) -> bool:
    return some_check():

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why
  • This PR fixes an issue.
  • 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, ...)

@Kile Kile changed the title Adding on_check_failure Adding on_check_failure to View class Jan 15, 2022
@plun1331
Copy link
Member

I feel like doing this in interaction_check is easier, mostly because you would know what condition failed.

The feature could have it's uses though.

@krittick
Copy link
Contributor

I think it would be best to just add the method itself (to allow subclassing and better code organization) but not provide a default behavior (i.e. don't auto-defer on failure).

@Kile
Copy link
Contributor Author

Kile commented Jan 15, 2022

I don't mind changing it to that if you'd like me to

@Lulalaby Lulalaby added this to the v2.1 milestone Jan 18, 2022
@Lulalaby Lulalaby marked this pull request as draft January 22, 2022 01:19
@VincentRPS VincentRPS added feature Implements a feature Merge normally priority: low Low Priority status: planned Planned in the future labels Jan 26, 2022
Dorukyum
Dorukyum previously approved these changes Apr 5, 2022
@Dorukyum Dorukyum requested a review from krittick April 5, 2022 14:34
@plun1331
Copy link
Member

plun1331 commented May 6, 2022

Is anything going to happen with this for 2.0?

@krittick
Copy link
Contributor

krittick commented May 6, 2022

Is anything going to happen with this for 2.0?

It's marked as a 2.1 feature and still in draft.

Lulalaby
Lulalaby previously approved these changes May 6, 2022
@Lulalaby Lulalaby dismissed stale reviews from Dorukyum and themself via 8a29174 June 24, 2022 22:39
@Lulalaby Lulalaby requested review from Dorukyum and Lulalaby June 24, 2022 22:40
@Lulalaby Lulalaby removed the request for review from krittick June 24, 2022 22:40
@Kile Kile marked this pull request as ready for review June 25, 2022 23:45
@Lulalaby Lulalaby enabled auto-merge (squash) July 10, 2022 03:44
Copy link
Member

@baronkobama baronkobama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good to me. 👍

@Pycord-Development Pycord-Development deleted a comment from codecov bot Jul 11, 2022
@Lulalaby Lulalaby merged commit 17af9d0 into Pycord-Development:master Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Implements a feature priority: low Low Priority status: planned Planned in the future

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

8 participants