@YPAGAAH

Как сделать, чтобы при отправке данных из одной формы появлялось сообщение c другой кнопкой?

Бот с двумя кнопками, которые вызываются командами.
На данный момент при заполнении одной из форм отправляется сообщение с текстом.
Помогите сделать так, чтобы после заполнения формы отправлялось сообщение с другой формой.

import discord
from discord import ui
from discord.ext import commands

PREFIX = "/"
intents = discord.Intents().all()

#права бота
bot = commands.Bot(command_prefix=PREFIX, intents=intents)


class Questionnaire1(ui.Modal, title='Vouchform 1'):

    first_name = ui.TextInput(label='What is you Steam ID/Epic ID?')
    name = ui.TextInput(label='What is your main Implant ID & Gamename?')
    father_name = ui.TextInput(label='What are your alt Implant ID & Gamename?')
    nickname = ui.TextInput(label='How old are you?')
    
    async def on_submit(self, interaction: discord.Interaction):
        await interaction.response.send_message(f"Fill out vouch form 2", ephemeral=True)
        for channel in interaction.guild.text_channels:
            if 'заявки' == channel.name:
                await channel.send(f"Vouchform 1\n"
                                   f"Discord: {interaction.user.name}\n"
                                   f"Steam ID: {self.first_name}\n"
                                   f"ImplantID&Nickname: {self.name}\n"
                                   f"alt ImplantID&Nickname: {self.father_name}\n"
                                   f"Age: {self.nickname}")
                break

class Questionnaire2(ui.Modal, title='Vouchform 2'):
    first_name = ui.TextInput(label='WHAT IS YOUR TIMEZONE?')
    name = ui.TextInput(label='WHAT LANGUAGES DO YOU SPEAK?')
    father_name = ui.TextInput(label='WHAT WERE YOUR PREVIOUS TRIBE?')
    nickname = ui.TextInput(label='WHO VOUCHED FOR YOU?')

    async def on_submit(self, interaction: discord.Interaction):
        await interaction.response.send_message(f'The application will be reviewed by the administrator', ephemeral=True, delete_after=30)
        for channel in interaction.guild.text_channels:
            if 'заявки' == channel.name:
                await channel.send(f"Vouchform2\n"
                                   f"Discord: {interaction.user.name}\n"
                                   f"TIMEZONE: {self.first_name}\n"
                                   f"LANGUAGES: {self.name}\n"
                                   f"TRIBES: {self.father_name}\n"
                                   f"WHO VOUCH: {self.nickname}")
                break

@bot.command()
async def invite(ctx):

    button = discord.ui.Button(label="Vouchform", style=discord.ButtonStyle.green)

    async def button_callback(interaction: discord.Interaction):
        q = Questionnaire1()
        await interaction.response.send_modal(q)

    view = discord.ui.View()
    view.add_item(button)
    button.callback = button_callback
    await ctx.send(view=view)


@bot.command()
async def invite2(ctx):
    button = discord.ui.Button(label="Vouchform 2", style=discord.ButtonStyle.green)

    async def button_callback(interaction: discord.Interaction):
        q = Questionnaire2()
        await interaction.response.send_modal(q)

    view = discord.ui.View()
    view.add_item(button)
    button.callback = button_callback
    await ctx.send(view=view)
  • Вопрос задан
  • 79 просмотров
Решения вопроса 1
@YPAGAAH Автор вопроса
Надеюсь кому-то поможет.
Проблема решилась таким образом:
Создал отдельные классы для каждой кнопки и вызвал класс кнопки в send_message с помощью view=Button2()
await interaction.response.send_message(f'Fill out vouch form 2\n', view=Button2(), ephemeral=True, delete_after=30)
Код полностью:
import discord
from discord import ui
from discord.ext import commands

PREFIX = "/"
intents = discord.Intents().all()

#права бота
bot = commands.Bot(command_prefix=PREFIX, intents=intents)


class Button1(discord.ui.View):
    def __init__(self,):
        super().__init__(timeout=None)

    @discord.ui.button (label="Vouchform", style=discord.ButtonStyle.green, custom_id="button1")
    async def button_callback(self, interaction, button):
        q = Questionnaire1()
        await interaction.response.send_modal(q)


class Button2(discord.ui.View):
    def __init__(self,):
        super().__init__(timeout=None)

    @discord.ui.button (label="Vouchform2", style=discord.ButtonStyle.green, custom_id="button2")
    async def button_callback(self, interaction, button):
        q = Questionnaire2()
        await interaction.response.send_modal(q)

#Вызываем модальное окно
class Questionnaire1(ui.Modal, title='Vouchform 1'):

    first_name = ui.TextInput(label='What is you Steam ID/Epic ID?')
    name = ui.TextInput(label='What is your main Implant ID & Gamename?')
    father_name = ui.TextInput(label='What are your alt Implant ID & Gamename?')
    nickname = ui.TextInput(label='How old are you?')
    
    async def on_submit(self, interaction: discord.Interaction):
        await interaction.response.send_message(f'Fill out vouch form 2\n', view=Button2(), ephemeral=True, delete_after=60)
        for channel in interaction.guild.text_channels:
            if 'заявки' == channel.name:
                await channel.send(f"Vouchform 1\n"
                                   f"Discord: {interaction.user.name}\n"
                                   f"Steam ID: {self.first_name}\n"
                                   f"ImplantID&Nickname: {self.name}\n"
                                   f"alt ImplantID&Nickname: {self.father_name}\n"
                                   f"Age: {self.nickname}")
                break

class Questionnaire2(discord.ui.Modal, title='Vouchform 2'):

    first_name = ui.TextInput(label='WHAT IS YOUR TIMEZONE?')
    name = ui.TextInput(label='WHAT LANGUAGES DO YOU SPEAK?')
    father_name = ui.TextInput(label='WHAT WERE YOUR PREVIOUS TRIBE?')
    nickname = ui.TextInput(label='WHO VOUCHED FOR YOU?')

    async def on_submit(self, interaction: discord.Interaction):
        await interaction.response.send_message(f'The application will be reviewed by the administrator\n', ephemeral=True, delete_after=30)
        for channel in interaction.guild.text_channels:
            if 'заявки' == channel.name:
                await channel.send(f"Vouchform2\n"
                                   f"Discord: {interaction.user.name}\n"
                                   f"TIMEZONE: {self.first_name}\n"
                                   f"LANGUAGES: {self.name}\n"
                                   f"TRIBES: {self.father_name}\n"
                                   f"WHO VOUCH: {self.nickname}")
                break

#создает кнопку invite нажатие на которую вызывает модальное окно
@bot.command()
async def invite(ctx):
        
        view = Button1()
        view.add_item = Button1.button_callback
        await ctx.send(view=view)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

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