英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论