#Compare buttons
1 messages · Page 1 of 1 (latest)
I have this button and in View.interaction_check I want to check if this button was pressed
ig you could use custom id
does it have any rules?
or best practices?
i remember someone made a 3rd party lib that helped with ids
making them persistent
It depends on what you have to do with the buttons, the most basic practice is to assign constant custom IDs for different buttons, buttons of the same view class will have the same IDs, other more complex uses involve the use of a prefix + some IDs to identify which user pressed the button etc (usually these custom IDs are used for persistent buttons sent as low level components)
maybe #disnake-compass
I need to make specific buttons of a View clickable by all members
and the rest only by interaction's author
async def interaction_check(self, interaction: disnake.MessageInteraction) -> bool:
if not self.message:
self.message = interaction.message
if (
self.author in {None, interaction.author}
or not self.shared
and interaction.component in self.shared_buttons
):
return True
await interaction.response.send_message(
_("interaction_not_allowed"), ephemeral=True
)
return False
interaction.component in self.shared_buttons is what returns False
Are your buttons all in the same view class?
yep
thats a simple embed paginator
i want the author to be able to share and unshare some buttons
share as in allow other to click
so they press the Lock button and toggle that behavior
since all buttons have to have a custom id, disnake assigns them automatically right?
so interaction.component has a custom id, but the buttons in the view class dont
and ig thats why they're not considered equal
if there's a good convention for custom ids, let me know
custom_id (Optional[str]) – The ID of the button that gets received during an interaction. It is recommended not to set this parameter to prevent conflicts.
could you explain this part too?
sorry I was busy
no
you need to assign them
property custom_id```
The ID of the button that gets received during an interaction.
If this button is for a URL, it does not have a custom ID.
but in the docs it says that all components must have an id
and i didnt specify anything
so it must be automatically generated if nothing is passed
then lemme check from source
sadly buttons dont implement eq check
disnake/ui/button.py lines 129 to 131
self._provided_custom_id = custom_id is not None
if url is None and custom_id is None:
custom_id = os.urandom(16).hex()
yea
if you open an issue I could work on it later
btw you can do it too without an eq, assigning a custom id