Задать вопрос
Zagir-vip
@Zagir-vip
Web dev, Game dev, app dev, Разработчик на Python!

Discord Embed Текст и кнопка в одной строке?

69793a20cc641200593387.jpeg

на фото сообщение от бота и при нажатии на кнопку открывается модальное окно
  • Вопрос задан
  • 69 просмотров
Подписаться 1 Средний 2 комментария
Помогут разобраться в теме Все курсы
  • Нетология
    1C-программист: расширенный курс
    18 месяцев
    Далее
  • Академия Eduson
    Python-разработчик
    9 месяцев
    Далее
  • Skillbox
    Профессия 1С-программист
    8 месяцев
    Далее
Решения вопроса 1
@dim5x
ЗИ, ИБ. Помогли? Поблагодарите. Отметьте ответом.
Использовать UI v2 компоненты. В dev версии disnake.py.
pip uninstall disnake -y
pip install -U git+https://github.com/DisnakeDev/disnake.git

Код
import os
import disnake
from disnake.ext import commands
from disnake import ui

TOKEN = os.environ['TOKEN_DISCORD']

bot = commands.InteractionBot()

@bot.slash_command(name="support", description="Система поддержки")
async def support(inter: disnake.ApplicationCommandInteraction):
    await inter.response.send_message(
        components=[
            ui.Container(
                ui.TextDisplay(
                    content=(
                        "## Система поддержки\n"
                        "Выберите тип обращения, а сотрудники нашего сообщества "
                        "своевременно и качественно помогут решить это."
                    )
                ),
                ui.TextDisplay(content="### Жалобы"),
                ui.Section(
                    ui.TextDisplay(content="Жалоба на игрока"),
                    accessory=ui.Button(
                        emoji="",
                        style=disnake.ButtonStyle.secondary,
                        custom_id="complaint_player"
                    )
                ),
                ui.Section(
                    ui.TextDisplay(content="Жалоба на персонал"),
                    accessory=ui.Button(
                        emoji="️",
                        style=disnake.ButtonStyle.secondary,
                        custom_id="complaint_staff"
                    )
                ),
                ui.Separator(),
                ui.TextDisplay(content="### Заявки"),
                ui.Section(
                    ui.TextDisplay(content="Подать апелляцию"),
                    accessory=ui.Button(
                        emoji="",
                        style=disnake.ButtonStyle.secondary,
                        custom_id="appeal"
                    )
                ),
                ui.Separator(),
                ui.TextDisplay(content="### Улучшения"),
                ui.Section(
                    ui.TextDisplay(content="Сообщить о баге"),
                    accessory=ui.Button(
                        emoji="",
                        style=disnake.ButtonStyle.secondary,
                        custom_id="bug_report"
                    )
                ),
                ui.Section(
                    ui.TextDisplay(content="Предложить улучшение"),
                    accessory=ui.Button(
                        emoji="⚙️",
                        style=disnake.ButtonStyle.secondary,
                        custom_id="suggestion"
                    )
                ),
                ui.Separator(),
                ui.TextDisplay(content="### Верификация"),
                ui.Section(
                    ui.TextDisplay(content="Заявка роль 18+"),
                    accessory=ui.Button(
                        emoji="",
                        style=disnake.ButtonStyle.secondary,
                        custom_id="verify_18"
                    )
                ),
                accent_colour=disnake.Colour.from_rgb(249, 134, 106),
            ),

            # Select ВСЕГДА ВНЕ Container
            ui.StringSelect(
                placeholder="❓ Частые вопросы",
                custom_id="faq_select",
                options=[
                    disnake.SelectOption(label="Как подать жалобу?", value="faq_complaint"),
                    disnake.SelectOption(label="Сколько рассматривается заявка?", value="faq_time"),
                    disnake.SelectOption(label="Куда отправляются обращения?", value="faq_where"),
                ]
            )
        ]
    )


# ───── Обработчик кнопок ─────
@bot.listen("on_button_click")
async def on_button(inter: disnake.MessageInteraction):
    cid = inter.component.custom_id

    modal = ui.Modal(
        title="Обращение в поддержку",
        custom_id=f"modal_{cid}",
        components=[
            ui.TextInput(
                label="Опишите проблему",
                custom_id="text",
                style=disnake.TextInputStyle.paragraph,
                required=True,
                max_length=1000,
            )
        ],
    )

    await inter.response.send_modal(modal)

bot.run(TOKEN)


P.S. хабр пожрал эмодзи в коде.

697a7419034c4388382280.png
697a4dd6c8dcd957275224.png
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

Похожие вопросы