Надеюсь кому-то поможет.
Проблема решилась таким образом:
Создал отдельные классы для каждой кнопки и вызвал класс кнопки в 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="Invite1")
async def button_callback(self, interaction, button):
q = Questionnaire1()
button.callback = Button1.button_callback
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="Invite2")
async def button_callback(self, interaction, button):
q = Questionnaire2()
button.callback = Button2.button_callback
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)