python 无法在pycord中正确显示按钮

enxuqcxy  于 2023-01-04  发布在  Python
关注(0)|答案(1)|浏览(136)

我有一个视图类:

class genagain(discord.ui.View):

    @discord.ui.button(label="U1", style=discord.ButtonStyle.primary, custom_id="u1", row=0)
    async def button_callback(self, button, interaction):
        await interaction.response.defer()
        await interaction.response("Generating again...")
        
    @discord.ui.button(label="U2", style=discord.ButtonStyle.primary, custom_id="u2", row=0)
    async def button_callback(self, button, interaction):
        await interaction.response.defer()
        await interaction.response("Generating again...")
        
    @discord.ui.button(label="U3", style=discord.ButtonStyle.primary, custom_id="u3", row=0)
    async def button_callback(self, button, interaction):
        await interaction.response.defer()
        await interaction.response("Generating again...")
        
    @discord.ui.button(label="U4", style=discord.ButtonStyle.primary, custom_id="u4", row=0)
    async def button_callback(self, button, interaction):
        await interaction.response.defer()
        await interaction.response("Generating again...")
    
    @discord.ui.button(label="", style=discord.ButtonStyle.primary, emoji="🔄", custom_id="genagain", row=1)
    async def button_callback(self, button, interaction):
        await interaction.response.defer()
        await interaction.response("Generating again...")
        
    @discord.ui.button(label="V1", style=discord.ButtonStyle.primary, custom_id="v1", row=2)
    async def button_callback(self, button, interaction):
        await interaction.response.defer()
        await interaction.response("Generating again...")
        
    @discord.ui.button(label="V2", style=discord.ButtonStyle.primary, custom_id="v2", row=2)
    async def button_callback(self, button, interaction):
        await interaction.response.defer()
        await interaction.response("Generating again...")
    
    @discord.ui.button(label="V3", style=discord.ButtonStyle.primary, custom_id="v3", row=2)
    async def button_callback(self, button, interaction):
        await interaction.response.defer()
        await interaction.response("Generating again...")
    
    @discord.ui.button(label="V4", style=discord.ButtonStyle.primary, custom_id="v4", row=2)
    async def button_callback(self, button, interaction):
        await interaction.response.defer()
        await interaction.response("Generating again...")

代码应该做的是创建3行9个按钮,如果按下按钮,则响应“Generating again...”。
但结果是这样的:

为什么只显示最后一个按钮?

n1bvdmb6

n1bvdmb61#

每个按钮都需要自己的unique callback function。您是否尝试过重命名各种功能?

相关问题