Другие предложили добавить "await Interaction.interaction.response.defer(ephemeral = True)" в мой код, но это тоже не работает. Мне интересно, есть ли другой способ заставить это работать. Я озадачен модальными окнами. Скажите, пожалуйста, есть ли другой способ их работы.
Вот мой код:
Код: Выделить всё
import discord
from discord.ext import commands
from discord import ui
intents = discord.Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix="?",intents=intents.all())
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
@client.command()
async def check(ctx):
await ctx.send("What's up chat")
@client.command()
async def banana(ctx):
await ctx.send("banana")
@client.command(name="modaltest")
async def modaltest(interaction: discord.Interaction):
class MyModal(ui.Modal,title="Whatsup"):
answer=discord.ui.TextInput(label="(LABEL_",style=discord.TextStyle.short, placeholder="Yes",default="Yes/No",required=True)
async def on_submit(self, interaction: discord.Interaction):
await interaction.response.send_message("It's time")
await interaction.interaction.response.defer(ephemeral=True)
await interaction.response.send_modal(MyModal())
client.run('TOKEN')
Код: Выделить всё
[2024-04-06 19:57:56] [INFO ] discord.gateway: Shard ID None has connected to Gateway (Session ID: 81799a7cbd347820290acba7203ba543).
We have logged in as Test bot#2666
[2024-04-06 19:58:07] [ERROR ] discord.ext.commands.bot: Ignoring exception in command modaltest
Traceback (most recent call last):
File "C:\Users\abhyu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\core.py", line 235, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\abhyu\Desktop\python\main2.py", line 33, in modaltest
await interaction.interaction.response.defer(ephemeral=True)
AttributeError: 'NoneType' object has no attribute 'response'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\abhyu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\bot.py", line 1350, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\abhyu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\core.py", line 1029, in invoke
await injected(*ctx.args, **ctx.kwargs) # type: ignore
File "C:\Users\abhyu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\discord\ext\commands\core.py", line 244, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'response'
(Да, и еще вопрос, как получить ввод, отправленный пользователем из модальных окон)
Подробнее здесь: https://stackoverflow.com/questions/782 ... onse-error