Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.76k stars 3.75k forks source link

Make @discord.app_commands.default_permissions() take a Permissions object #9951

Open 2br-2b opened 3 hours ago

2br-2b commented 3 hours ago

Summary

Make @discord.app_commands.default_permissions() take a Permissions object

What is the feature request for?

The core library

The Problem

Right now, I can create a permissions object:

ADMIN_PERMISSIONS = Permissions(
    moderate_members=True
)

and I can add permissions to a function:

new_func = app_commands.default_permissions(moderate_members=True)(new_func)

but I can't pass a Permissions object to the default_permissions() decorator

# Doesn't work
new_func = app_commands.default_permissions(ADMIN_PERMISSIONS)(new_func)

Right now, the decorator just takes the permissions it's passed and creates an object anyway:

https://github.com/Rapptz/discord.py/blob/59f877fcf013c4ddeeb2b39fc21f03e76f995461/discord/app_commands/commands.py#L2860

So I don't see why I can't just pass a Permissions object.

The Ideal Solution

Either modify the default_permissions() decorator to optionally take a Permissions object or create a new decorator that does the same thing.

The Current Solution

  1. Create a function that converts a Permissions object into a list of arguments;
  2. Create a new decorator

Additional Context

Thank you so much for this incredible library!

2br-2b commented 3 hours ago

My current solution is to do:

new_func = app_commands.default_permissions(**dict(ADMIN_PERMISSIONS))(new_func)

and it works, but it feels ugly