• Disnake | Python | Реализация "Формы" как это сделать?

    fenrir1121
    @fenrir1121 Куратор тега discord.py
    Начни с документации
    Реализация «Формы» как это сделать?
    Открыть документацию и посмотреть

    Реализация в плане кода. Подойдёт простой пример создания "Формы"
    Ну ладно, откроем её
    вместо тебя
    import asyncio
    import os
    
    import disnake
    from disnake.ext import commands
    
    bot = commands.Bot(command_prefix=commands.when_mentioned)
    
    class MyModal(disnake.ui.Modal):
        def __init__(self) -> None:
            components = [
                disnake.ui.TextInput(
                    label="Name",
                    placeholder="The name of the tag",
                    custom_id="name",
                    style=disnake.TextInputStyle.short,
                    min_length=5,
                    max_length=50,
                ),
                disnake.ui.TextInput(
                    label="Content",
                    placeholder="The content of the tag",
                    custom_id="content",
                    style=disnake.TextInputStyle.paragraph,
                    min_length=5,
                    max_length=1024,
                ),
            ]
            super().__init__(title="Create Tag", custom_id="create_tag", components=components)
    
        async def callback(self, inter: disnake.ModalInteraction) -> None:
            tag_name = inter.text_values["name"]
            tag_content = inter.text_values["content"]
    
            embed = disnake.Embed(title=f"Tag created: `{tag_name}`")
            embed.add_field(name="Content", value=tag_content)
            await inter.response.send_message(embed=embed)
    
        async def on_error(self, error: Exception, inter: disnake.ModalInteraction) -> None:
            await inter.response.send_message("Oops, something went wrong.", ephemeral=True)
    
    @bot.slash_command()
    async def create_tag(inter: disnake.CommandInteraction):
        await inter.response.send_modal(modal=MyModal())
    
    @bot.event
    async def on_ready():
        print(f"Logged in as {bot.user} (ID: {bot.user.id})\n------")
    
    
    if __name__ == "__main__":
        bot.run(os.getenv("BOT_TOKEN"))
    Ответ написан
    1 комментарий