class HangmanButton(discord.ui.View):
def __init__(self, *, timeout=180):
super().__init__(timeout=timeout)
@discord.ui.button(label="Начать Игру", style=discord.ButtonStyle.gray)
async def button(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_modal(HangmanStartModal())
if interaction.user is not interaction.creator.author: return await interaction.response.send_message(embed = discord.Embed(title='❌| Ошибка', description='Вы не можете играть в своей собственной игре.', color=discord.Color.darker_grey()), ephemeral=True)
discord.Interaction 没有名为
creator
的属性。要获得原作者,您可以进行争论。然后,你可以用你自己的interaction_check
覆盖discord的检查。
class HangmanButton(discord.ui.View):
def __init__(self, author, timeout=180):
super().__init__(timeout=timeout)
self.author = author
@discord.ui.button(label="Начать Игру", style=discord.ButtonStyle.gray)
async def button(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.response.send_modal(HangmanStartModal())
async def interaction_check(self, interaction: discord.Interaction):
return interaction.user.id == self.author.id
因此,调用视图时:
HangmanButton(interaction.user) # or ctx.author/message.author where applicable