I'm making a discord.py bot and was testing my /settings command. It works fine but there is a problem: the dropdown appears after the buttons but I want it to be above.
Here is my code:
class Settings(discord.ui.View):
def __init__(self) -> None:
super().__init__()
self.value = None
self.build_options()
select = discord.ui.Select(options=self.options)
select.callback = self.select_option
self.add_item(select)
def build_options(self):
if get_name() == "":
self.options = [
discord.SelectOption(
label=" ",
default=True
)
]
else:
self.options = [
discord.SelectOption(
label=get_name(),
default=True
)
]
async def select_option(self, interaction: discord.Interaction, select: discord.ui.Select):
if select.values[0] == "None":
await interaction.response.send_message("None", ephemeral=True)
else:
await interaction.response.send_message("None", ephemeral=True)
@discord.ui.button(label="Add", emoji="<:add:1203694266573127680>", style=discord.ButtonStyle.success)
async def add_profile(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_modal(New())
@discord.ui.button(label="Edit", emoji="<:edit:1203694268473151558>", style=discord.ButtonStyle.secondary)
async def edit_profile(self, interaction: discord.Interaction, button: discord.ui.Button):
...
@discord.ui.button(label="Delete", emoji="<:trash:1204886545765503056>", style=discord.ButtonStyle.danger)
async def delete_profile(self, interaction: discord.Interaction, button: discord.ui.Button):
...
I've tried a lot of ways but none of them worked
Documentation says this about buttons:
row (Optional[int]) – The relative row this button belongs to. A Discord component can only have 5 rows. By default, items are arranged automatically into those 5 rows. If you’d like to control the relative positioning of the row then passing an index is advised. For example, row=1 will show up before row=2. Defaults to None, which is automatic ordering. The row number must be between 0 and 4 (i.e. zero indexed).
Select also has the same parameter.
This means that if you change the row
parameter, you can set their respective rows.
Your Code:
select = discord.ui.Select(options=self.options)
You could change the above to:
select = discord.ui.Select(options=self.options, row=0) # set the row
It should be the same process. See the documentation here