Change View callback order to (self, interaction, item)

This is more consistent with the rest of the library which always has
the interaction as the first parameter. This has been done before in
the command extension as well, the first parameter is always either
self or the context.
This commit is contained in:
Rapptz
2022-03-24 23:00:50 -04:00
parent f26d3a7155
commit 968a1f366f
8 changed files with 27 additions and 15 deletions

View File

@ -27,14 +27,14 @@ class Confirm(discord.ui.View):
# stop the View from listening to more input.
# We also send the user an ephemeral message that we're confirming their choice.
@discord.ui.button(label='Confirm', style=discord.ButtonStyle.green)
async def confirm(self, button: discord.ui.Button, interaction: discord.Interaction):
async def confirm(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message('Confirming', ephemeral=True)
self.value = True
self.stop()
# This one is similar to the confirmation button except sets the inner value to `False`
@discord.ui.button(label='Cancel', style=discord.ButtonStyle.grey)
async def cancel(self, button: discord.ui.Button, interaction: discord.Interaction):
async def cancel(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message('Cancelling', ephemeral=True)
self.value = False
self.stop()

View File

@ -25,7 +25,7 @@ class Counter(discord.ui.View):
# When it hits 5, the counter button is disabled and it turns green.
# note: The name of the function does not matter to the library
@discord.ui.button(label='0', style=discord.ButtonStyle.red)
async def count(self, button: discord.ui.Button, interaction: discord.Interaction):
async def count(self, interaction: discord.Interaction, button: discord.ui.Button):
number = int(button.label) if button.label else 0
if number + 1 >= 5:
button.style = discord.ButtonStyle.green

View File

@ -23,7 +23,7 @@ class Counter(discord.ui.View):
# When it hits 5, the counter button is disabled and it turns green.
# note: The name of the function does not matter to the library
@discord.ui.button(label='0', style=discord.ButtonStyle.red)
async def count(self, button: discord.ui.Button, interaction: discord.Interaction):
async def count(self, interaction: discord.Interaction, button: discord.ui.Button):
number = int(button.label) if button.label else 0
if number + 1 >= 5:
button.style = discord.ButtonStyle.green
@ -38,7 +38,7 @@ class EphemeralCounter(discord.ui.View):
# When this button is pressed, it will respond with a Counter view that will
# give the button presser their own personal button they can press 5 times.
@discord.ui.button(label='Click', style=discord.ButtonStyle.blurple)
async def receive(self, button: discord.ui.Button, interaction: discord.Interaction):
async def receive(self, interaction: discord.Interaction, button: discord.ui.Button):
# ephemeral=True makes the message hidden from everyone except the button presser
await interaction.response.send_message('Enjoy!', view=Counter(), ephemeral=True)

View File

@ -17,15 +17,15 @@ class PersistentView(discord.ui.View):
super().__init__(timeout=None)
@discord.ui.button(label='Green', style=discord.ButtonStyle.green, custom_id='persistent_view:green')
async def green(self, button: discord.ui.Button, interaction: discord.Interaction):
async def green(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message('This is green.', ephemeral=True)
@discord.ui.button(label='Red', style=discord.ButtonStyle.red, custom_id='persistent_view:red')
async def red(self, button: discord.ui.Button, interaction: discord.Interaction):
async def red(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message('This is red.', ephemeral=True)
@discord.ui.button(label='Grey', style=discord.ButtonStyle.grey, custom_id='persistent_view:grey')
async def grey(self, button: discord.ui.Button, interaction: discord.Interaction):
async def grey(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_message('This is grey.', ephemeral=True)