pycord icon indicating copy to clipboard operation
pycord copied to clipboard

Button's custom_id setter does set `_provided_custom_id` to `True`

Open akosjdlk-60 opened this issue 10 months ago • 2 comments

Summary

See tile

Reproduction Steps

See mrc

Minimal Reproducible Code

import os
import discord

class CustomView(discord.ui.View):
    def __init__(self):
        super().__init__(timeout=None)

        self.button = discord.ui.Button(label="Example") 
        self.button.custom_id = "custom_id"
        self.button.callback = self.callback

        self.add_item(self.button)

    async def callback(self, interaction: discord.Interaction):
        await interaction.respond("Button clicked!")

bot = discord.Bot(intents=discord.Intents.all())

@bot.slash_command(name="test")
async def test_modal(ctx: discord.ApplicationContext):
    view = CustomView()
    await ctx.respond(content=f"{view.is_persistent()=}\n{view.button.is_persistent()=}", view=view)

bot.run(os.getenv("TOKEN"))

Expected Results

Both button and view are persistent

Actual Results

Neither are actually persistent

Intents

all

System Information

  • Python v3.13.2-final
  • py-cord v2.6.1-final (I am on master)
  • aiohttp v3.11.16
  • system info: Linux 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025

Checklist

  • [x] I have searched the open issues for duplicates.
  • [x] I have shown the entire traceback, if possible.
  • [x] I have removed my token from display, if visible.

Additional Context

Discord conversation: https://discord.com/channels/881207955029110855/1132206148309749830/1362790146553942199

akosjdlk-60 avatar Apr 18 '25 14:04 akosjdlk-60

should be fixed in #2707

Lumabots avatar Apr 30 '25 19:04 Lumabots

should be fixed in #2707

If confirmed, #2707 should be marked as fixing this issue

Paillat-dev avatar Apr 30 '25 19:04 Paillat-dev

~~Can repro, is not fixed by #2707 nor #2904 ~~

Paillat-dev avatar Oct 21 '25 11:10 Paillat-dev

The setter for Button.custom_id does set the attribute on the latest commit: https://github.com/Pycord-Development/pycord/blob/ca91b3e22d9f521dbb6f1da4595efea7093fc276/discord/ui/button.py#L187

I cannot repro this.

import discord

button = discord.ui.Button(label="hello")
button.custom_id = "my_custom_id"
print(
    button.custom_id,  # my_custom_id 
    type(button.custom_id),  # <class 'str'>
    button.is_persistent(),  # True
    button._provided_custom_id,  # True
) #  True True


button2 = discord.ui.Button(label="hello", custom_id="another_custom_id")
print(
    button2.custom_id,  # another_custom_id 
    type(button2.custom_id),  # <class 'str'>
    button2.is_persistent(),  # True
    button2._provided_custom_id,  # True
) # <class 'str'> True True


button3 = discord.ui.Button(label="hello")
print(
    button3.custom_id,  # a0070e0ae1a349e5445045c674c15e33 
    type(button3.custom_id),  # <class 'str'>
    button3.is_persistent(),  # False
    button3._provided_custom_id,  # False
)

I think you forgot to call Bot.add_view, this makes it actually persistent.

Soheab avatar Oct 21 '25 12:10 Soheab