import disnake
from disnake.ext import commands
from disnake import TextInputStyle
bot = commands.Bot()
# Кнопки принятия/отказа заявки
class AcceptPlayer(disnake.ui.View):
def __init__(self, author):
super().__init__(timeout = None)
self.author = author
@disnake.ui.button(label = "Принять", style = disnake.ButtonStyle.success)
async def acceptButton(self, button: disnake.ui.Button, inter: {disnake.AppCmdInter, disnake.ModalInteraction}):
await inter.send(f"Принят {inter.author.mention}", ephemeral = True)
AcceptMessage = disnake.Embed(
title = "Принято"
)
await self.author.send(embed = AcceptMessage)
disnake.Button.disabled = True
@disnake.ui.button(label = "Отклонить", style = disnake.ButtonStyle.red)
async def rejectButton(self, button: disnake.ui.Button, inter: {disnake.AppCmdInter, disnake.ModalInteraction}):
await inter.send(f"Отклонён {inter.author.mention}", ephemeral = True)
RejectMessage = disnake.Embed(
title = "Отклонено"
)
await self.author.send(embed = RejectMessage)
disnake.Button.disabled = True
# Модальное окно
class Request(disnake.ui.Modal):
def __init__(self):
components = [
disnake.ui.TextInput(
label = "Никнейм",
placeholder = "Ваш никнейм",
custom_id = "Никнейм",
style = TextInputStyle.short,
max_length = 15,
),
disnake.ui.TextInput(
label = "Возраст",
placeholder = "18 лет",
custom_id = "Возраст",
style = TextInputStyle.short,
max_length = "10"
),
disnake.ui.TextInput(
label = "О себе",
placeholder = "Коротко о себе",
custom_id = "Описание",
style = TextInputStyle.paragraph,
),
disnake.ui.TextInput(
label = "Что вы планируете делать?",
placeholder = "Чем планируете заниматься на сервере?",
custom_id = "Что будете делать",
style = TextInputStyle.paragraph,
),
]
super().__init__(
title="Заполнение заявки",
custom_id="Заявка",
components=components,
)
# Обработка ответа, после отправки
async def callback(self, inter: disnake.ModalInteraction):
requestEmbed = disnake.Embed(
title = "Новая заявка!",
description = f"**Отправитель: {inter.user.global_name}**",
color = disnake.Colour.red(),
)
requestEmbed.set_thumbnail(url = inter.user.display_avatar.url)
for key, value in inter.text_values.items():
requestEmbed.add_field(
name = key.capitalize(),
value = value[:1024],
inline = False,
)
await inter.response.send_message(content="Вы успешно заполнили анкету!", ephemeral=True)
channel = bot.get_channel(1298632551254196277)
await channel.send(embed = requestEmbed, view = AcceptPlayer(inter.author))
requestCallBackEmbed = disnake.Embed(
title = "Ваша заявка отправлена на рассмотрение!",
description = "***На рассмотрение заявок уходит до 24-х часов***",
color = disnake.Colour.purple(),
)
requestCallBackEmbed.set_image(file = disnake.File("reference/static.png"))
requestCallBackEmbed.set_thumbnail(file = disnake.File("reference/miniature.jpg"))
await inter.author.send(embed = requestCallBackEmbed)
@bot.slash_command(
name = "tester"
)
async def tags(inter: disnake.AppCmdInter):
await inter.response.send_modal(modal = Request())
with open("token.env") as file:
token = file.read()
bot.run(token)
