Как исправить ошибку когда я пытаюсь создать/использовать Modal? (код и ошибка есть в описании)
Код:
# пытаюсь сделать так что бы участник вводил что-то в всплывающем окне
class MyModal(discord.ui.Modal, title='Title'):
answer = discord.ui.TextInput(label='Name', style=discord.TextStyle.short, placeholder='PlaceHolder', max_length=15)
async def on_submit(self, interaction: discord.Interaction):
embed = discord.Embed(title=self.title, description=f"**{self.answer.label}**\n{self.answer}.", color=discord.Color.blue)
await interaction.response.send_message(embed=embed)
# кнопка для вызова MyModal()
class Menu(discord.ui.View):
def __init__(self):
super().__init__()
@discord.ui.button(label='Отправить сообщение', style=discord.ButtonStyle.gray)
async def menu1(self, interaction:discord.Interaction, button:discord.ui.Button):
modal = MyModal()
await interaction.response.send_modal(modal=modal)
# вызов команды которая по идеи должна запрашивать у пользователя что-то
@bot.command()
async def modal(ctx):
view = Menu()
await ctx.send('Hi', view=view)
Выдаёт ошибку:
ERROR discord.ui.view Ignoring exception in view <Menu timeout=180.0 children=1> for item <Button style=<ButtonStyle.secondary: 2> url=None disabled=False label='Отправить сообщение' emoji=None row=None>
Traceback (most recent call last):
File "C:\Users\User1\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ui\view.py", line 425, in _scheduled_task
await item.callback(interaction)
File "c:\Users\User1\Documents\Discord_Bots\Tiket_bot\main.py", line 119, in menu1
await interaction.response.send_modal(modal=modal)
TypeError: InteractionResponse.send_modal() got some positional-only arguments passed as keyword arguments: 'modal'
Ответы (1 шт):
Автор решения: q r t s
→ Ссылка
В вашей строке ошибка:
await interaction.response.send_modal(modal=modal)
Уберите modal=:
modal = MyModal()
await interaction.response.send_modal(modal)