Vadok
@Vadok

Как записать данные пользователей?

бот должен принимать заявки людей и отправлять сообщение с данными в специальный канал (тут в два), но по задумке когда модератор нажимает "Принять" то бот автоматически связывается с MCRcon и добавляет человека в whitelist, но модальное окно и сообщение по сути не связаны, значит данные надо куда-то записывать, а по нажатию кнопки читать и передавать в команду whitelist, но как это сделать я придумать не смог(

import disnake
from disnake.ext import commands
from disnake import TextInputStyle
from disnake import utils
import json
from mcrcon import MCRcon

bot = commands.Bot(command_prefix="!")


class MyModal(disnake.ui.Modal):
    def __init__(self):

        # The details of the modal, and its components
        components = [
                disnake.ui.TextInput(
                   label="Ник",
                    placeholder="Введите свой ник",
                    custom_id="Ник:",
                    style=TextInputStyle.short,
                    max_length=20,
                ),
                disnake.ui.TextInput(
                    label="Сколько вам лет?",
                    placeholder="Введите свой возраст",
                    custom_id="Возраст:",
                    style=TextInputStyle.short,
                    max_length=4,
                ),
                disnake.ui.TextInput(
                    label="Чем хотите заняться?",
                    placeholder="Чем хотите заняться?",
                    custom_id="Занятие:",
                    style=TextInputStyle.short,
                    max_length=100,
                ),
                disnake.ui.TextInput(
                    label="От кого узнали о нас?",
                    placeholder="От кого узнали?",
                    custom_id="От кого:",
                    style=TextInputStyle.short,
                    max_length=20
                ),
                disnake.ui.TextInput(
                    label="Java или Bedrock?",
                    placeholder="Java или Bedrock",
                    custom_id="Платформа:",
                    style=TextInputStyle.short,
                    max_length=10,
                ),
            ]
        super().__init__(title="Заявка", components=components, timeout=60)

    # The callback received when the user input is completed.
    async def callback(self, inter: disnake.ModalInteraction):
        await inter.response.send_message("Вы успешно подали заявку! после рассмотрения вы получите уведомление в личные сообщения.", ephemeral = True)

        autor = inter.author.id
        channel = bot.get_channel(1061764267944185898)
        channel2 = bot.get_channel(1105875621835456662)

        embed = disnake.Embed(title="____НОВАЯ ЗАЯВКА____", color=disnake.Colour.green())
        for key, value in inter.text_values.items():
            embed.add_field(
                name=key.capitalize(),
                value=value[:1024],
                inline=False,
            )
        embed.add_field(name="Отправитель:", value=f"<@{autor}>", inline=True)
        await channel.send("<@816989119980372008>", embed=embed, components=[
            disnake.ui.Button(label="Принять", style=disnake.ButtonStyle.green, custom_id="YES"),
            disnake.ui.Button(label="Отклонить", style=disnake.ButtonStyle.red, custom_id="NO"),
            disnake.ui.Button(label="Бедрок", style=disnake.ButtonStyle.gray, custom_id="Bedrock"),

            ],
        )
        await channel2.send(embed=embed)




@bot.command()
async def buttons(inter: disnake.ApplicationCommandInteraction):
    await inter.response.send_message(
        "Подать заявку",
        components=[
            disnake.ui.Button(label="Подать", style=disnake.ButtonStyle.success, custom_id="zayavka"),
        ],
    )


@bot.listen("on_button_click")
async def help_listener(inter: disnake.MessageInteraction):
    channel = bot.get_channel(1061764267944185898)

    if inter.component.custom_id not in ["zayavka"]:
        # We filter out any other button presses except
        # the components we wish to process.
        return

    if inter.component.custom_id == "zayavka":
        await inter.response.send_modal(modal=MyModal())

@bot.listen("on_button_click")
async def help_listener(inter: disnake.MessageInteraction):
    if inter.component.custom_id not in ["YES"]:
        # We filter out any other button presses except
        # the components we wish to process.
        return

    if inter.component.custom_id == "YES":
        await inter.response.send_message("Одобрено", ephemeral = True)

@bot.listen("on_button_click")
async def help_listener(inter: disnake.MessageInteraction):
    if inter.component.custom_id not in ["NO"]:
        # We filter out any other button presses except
        # the components we wish to process.
        return

    if inter.component.custom_id == "NO":
        await inter.response.send_message("Отклонено", ephemeral = True)

@bot.listen("on_button_click")
async def help_listener(inter: disnake.MessageInteraction):
    if inter.component.custom_id not in ["Bedrock"]:
        # We filter out any other button presses except
        # the components we wish to process.
        return

    if inter.component.custom_id == "Bedrock":
        await inter.response.send_message("Одобрено", ephemeral = True)
bot.run("token")
  • Вопрос задан
  • 78 просмотров
Решения вопроса 1
Vadok
@Vadok Автор вопроса
Решил
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы