Buttons won't work (possibly in cogs)
Summary
I am attempting to transition from discord.py to pycord, but my buttons just don't call the callback anymore for some reason
Reproduction Steps
Try the code and click a button
Minimal Reproducible Code
# Call this from a cog:
embed = discord.Embed(title="Title", colour=0x3498DB)
option_picked, view_object = await generate_option_picker(ctx, embed, 5)
if option_picked is None:
return
# It should run this:
class OptionPickerButton(discord.ui.Button['OptionPickerView']):
def __init__(self, number: int):
super().__init__(style=discord.ButtonStyle.blurple, label=str(number), row=(number-1)//5)
async def callback(self, interaction: discord.Interaction):
print("This won't run for some reason...")
if self.view.ctx.author.id == interaction.user.id or interaction.user.id == 244543752889303041:
print("Picked option", self.label)
await self.view.picked_option(int(self.label))
else:
await interaction.response.send_message("This isn't your command!\nYou can run this command yourself to explore this menu!", ephemeral=True)
class OptionPickerView(discord.ui.View):
def __init__(self, ctx: commands.Context, number_of_options: int):
super().__init__()
self.ctx: commands.Context = ctx
self.value: Optional[int] = None
for label in range(1, number_of_options+1):
self.add_item(OptionPickerButton(number=label))
print("This init completes properly too.")
async def picked_option(self, number):
self.value: int = number
for button in self.children:
button.disabled = True
print("Done")
await self.message.edit(view=self)
self.stop()
async def on_timeout(self):
try:
for button in self.children:
button.disabled = True
await self.message.edit(view=self)
except discord.errors.NotFound:
pass
async def generate_option_picker(ctx: commands.Context, embed: discord.Embed, number_of_options: int):
print("This will run no problem, as it should")
view: OptionPickerView = OptionPickerView(ctx=ctx, number_of_options=number_of_options)
view.message = await ctx.send(embed=embed, view=view)
print("Waiting...")
await view.wait()
return view.value, view
Expected Results
the function returns a number, 1-5 or None if it timed out
Actual Results
Interaction failed, nothing
Intents
messages=True, guilds=True, emojis=True
System Information
It errors for some reason? I also tried it with python -m pip install git+https://github.com/Pycord-Development/pycord
Traceback (most recent call last):
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\__main__.py", line 300, in <module>
main()
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\__main__.py", line 297, in main
args.func(parser, args)
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\__main__.py", line 52, in core
show_version()
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\__main__.py", line 41, in show_version
pkg = pkg_resources.get_distribution('pycord')
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\__init__.py", line 466, in get_distribution
dist = get_provider(dist)
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\__init__.py", line 342, in get_provider
return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\__init__.py", line 886, in require
needed = self.resolve(parse_requirements(requirements))
File "C:\Users\\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\__init__.py", line 772, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pycord' distribution was not found and is required by the application
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
https://discord.com/channels/881207955029110855/881309496385884180/893222519346180146 @BobDotCom
Possibly a duplicate of #192?
Based on your traceback, I believe this should be fixed by #214.
Confirmed duplicate of #192.