AttributeError: ‘submitButton’ 对象没有属性 ‘_row’ – Discord.py

huangapple go评论59阅读模式
英文:

AttributeError: 'submitButton' object has no attribute '_row' - Discord.py

问题

AttributeError: 'submitButton' 对象没有属性 '_row'

class submitButton(discord.ui.Button):
def __init__(self):

    @discord.ui.button(label="提交条目", style=discord.ButtonStyle.blurple, row=3)
    async def submitEntry(self, button: discord.ui.Button, interaction: 
                          discord.Interaction):

        await self.view.submit_response(interaction)
async def submit_response(self, interaction:discord.Interaction):
    
    # 在这里创建了 messageEmbed #
    
    await interaction.user.send(embed=messageEmbed)
    await interaction.response.send_message(content="您的答案已提交!", view=self, ephemeral=True, delete_after=30)
英文:

I keep getting this error for a Discord.py button and after searching the internet I still cant find out why it is happening.

Any help would be greatly appreciated.

Thanks!

AttributeError: 'submitButton' object has no attribute '_row'

    class submitButton(discord.ui.Button):
    def __init__(self):

        @discord.ui.button(label="Submit Entry", style=discord.ButtonStyle.blurple, row=3)
        async def submitEntry(self, button: discord.ui.Button, interaction: 
                              discord.Interaction):

            await self.view.submit_response(interaction)
    async def submit_response(self, interaction:discord.Interaction):
        
        # Created messageEmbed here #
        
        await interaction.user.send(embed=messageEmbed)
        await interaction.response.send_message(content="Your answers have been 
                                                submitted!", view=self, ephemeral=True, 
                                                delete_after=30)

答案1

得分: 1

出错是因为您在定义__init__时放置了按钮。通常,您应该像这样定义__init__

class submitButton(discord.ui.Button):
    def __init__(self):
        super().__init__()

另外,您的缩进有误(虽然这可能只是您在问题中粘贴的方式不对)。在__init__之外,您应该添加您的按钮。

class submitButton(discord.ui.Button):
    def __init__(self):
        super().__init__()
    
    @discord.ui.button(label="Submit Entry", style=discord.ButtonStyle.blurple, row=3)
    async def submitEntry(self, button: discord.ui.Button, interaction: discord.Interaction):
        await self.view.submit_response(interaction)
英文:

The error occurred because you put your button when defining __init__. You usually define __init__ as follows:

class submitButton(discord.ui.Button):
    def __init__(self):
        super().__init__()

Also your indentation is wrong (although that might just be how you pasted it in the question). OUTSIDE of __init__ should you add your buttons.

class submitButton(discord.ui.Button):
    def __init__(self):
        super().__init__()
    @discord.ui.button(label="Submit Entry", style=discord.ButtonStyle.blurple, row=3)
        async def submitEntry(self, button: discord.ui.Button, interaction: discord.Interaction):
            await self.view.submit_response(interaction)

huangapple
  • 本文由 发表于 2023年3月31日 16:40:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75896502.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定