所以,我想在我们的服务器上做一个结婚系统,但有一些按钮错误:
@client.tree.command(name='marry', description="Suggest to marry", )
async def marry(interaction: discord.Interaction, user: discord.Member):
print(f'{interaction.user}||{user}')
if interaction.user == user:
await interaction.response.send_message(content=f"{interaction.user.mention} you can`t marry yourself :(")
return
else:
embed_marry = discord.Embed(title='WOW.....', description=f'{interaction.user.mention} suggest a marry to {user.mention}', color=0x774dea)
await interaction.response.send_message(embed=embed_marry, view=MarryButtons())
class MarryButtons(discord.ui.View):
def __init__(self):
super().__init__()
#Green button under merry_embed in "async def marry"
@discord.ui.button(label="Yes", style=discord.ButtonStyle.success)
async def agree_btn(self, interaction: discord.Interaction, button: discord.ui.Button, user: discord.Member):
embed_agree = discord.Embed(title=f'{user.mention} answered YES', description=f'{user.mention} now married to {interaction.user.mention}')
await interaction.response.send_message(embed=embed_agree)
# Red button under merry_embed in "async def marry"
@discord.ui.button(label="No", style=discord.ButtonStyle.danger)
async def disagree_btn(self, interaction: discord.Interaction, button: discord.ui.Button, user: discord.Member):
embed_disagree = discord.Embed(title=f'{user.mention} answered NO', description=f'{user.mention} declined propose from {interaction.user.mention}')
await interaction.response.send_message(embed=embed_disagree)
# Gray emoji button under merry_embed in "async def marry"
@discord.ui.button(label="😜", style=discord.ButtonStyle.gray)
async def emoji_btn(self, interaction: discord.Interaction, button: discord.ui.Button, user: discord.Member):
embed_emoji = discord.Embed(title=f'{user.mention} canceled propose', description=f'Nothing changed')
await interaction.response.send_message(embed=embed_emoji)
字符串
总的来说,它看起来不错,但当我试图点击它们时,出现了一个不和谐的“交互错误”。discord.py
1条答案
按热度按时间kq4fsx7k1#
由于对错误本身缺乏了解,我看到的错误是您在按钮中放置了用户变量。
第一个月
删除变量,交互将继续。
async def agree_btn(self, interaction: discord.Interaction, button: discord.ui.Button:
个user
变量并使用命令更改其值。然后您可以在按钮类中访问它。第二个选项是database或json,用于多个请求句柄 *