import disnake
from disnake.ext import commands
from collections import defaultdict
bot = commands.Bot(command_prefix=commands.when_mentioned)
interactions = defaultdict(MyModal)
class MyModal(disnake.ui.Modal):
def __init__(self) -> None:
components = [
disnake.ui.TextInput(
label="Ваш ник:",
placeholder="Введите ваш никнейм",
custom_id="никнейм",
style=disnake.TextInputStyle.single_line,
min_length=1,
max_length=50,
),
disnake.ui.TextInput(
label="Ссылка на скриншот подарка:",
placeholder="Вставьте ссылку на скриншот подарка",
custom_id="скриншот",
style=disnake.TextInputStyle.paragraph,
min_length=1,
max_length=1024,
),
]
super().__init__(title="Create Tag", custom_id="create_tag", components=components)
async def callback(self, inter: disnake.MessageInteraction) -> None:
nick_name = inter.text_values["никнейм"]
screenshot_link = inter.text_values["скриншот"]
embed = disnake.Embed(title=f"Заявка на роль от `{nick_name}`")
embed.add_field(name="Ссылка на скриншот подарка", value=screenshot_link)
# Отправка результатов в указанный канал
if self.result_channel:
await self.result_channel.send(embed=embed)
await inter.response.send_message(embed=embed)
@bot.event
async def on_interaction(inter: disnake.Interaction):
if isinstance(inter, disnake.MessageInteraction):
if inter.message.components and inter.data['custom_id'] == "open_form_button":
# Создаем модальное окно и указываем канал для результатов
modal = interactions[inter.message.id]
modal.result_channel_id = 900354293155123252
# Отправляем сообщение с модальным окном
components = [disnake.ui.ActionRow(modal.components)]
message = await inter.channel.send("Открываем форму заявки...", components=components)
interactions[message.id] = modal
@bot.event
async def on_button_click(inter: disnake.MessageInteraction):
if inter.message.id in interactions:
# Обрабатываем взаимодействие кнопки в контексте модального окна
await interactions[inter.message.id].button_callback(inter)
@bot.slash_command()
async def заявка(inter: disnake.CommandInteraction):
result_channel_id = 900354293155123252 # ID канала для результатов
modal = interactions[inter.message.id]
modal.result_channel = bot.get_channel(result_channel_id)
button_message = await inter.channel.send("Нажмите кнопку, чтобы открыть форму заявки!", components=[
disnake.ui.Button(label="Открыть форму", custom_id="open_form_button")])
@bot.event
async def on_ready():
print(f"Logged in as {bot.user} (ID: {bot.user.id})\n------")
if name == "main":
bot.run("TOKEN")
I tried a lot of things, the bot had to open a form with questions by clicking on the button