G
G
Georgy Kharitonov2022-01-16 15:40:28
Python
Georgy Kharitonov, 2022-01-16 15:40:28

Test on discord.py. How to do?

So I want to create a test command in discord.py, and I think it’s clear what its meaning is. I want to somehow do this through the Select menu from dislash.py. Something like that:

from dislash import InteractionClient, SelectMenu, SelectOption
...
inter_client = InteractionClient(bot)
...
@bot.command()
async def test(ctx, correct = None, b = None,c = None ,d = None):
    await ctx.channel.purge(limit = 1)
    if correct == None and b == None:
        await ctx.send(f'{author.mention},Добавь верный вариант ответа и второй вариант ответа')
        return
    elif correct != None and b == None:
        await ctx.send(f'{author.mention} Добавь второй вариант ответа!')
        return
    elif correct != None and b != None and c == None:
        msg = await ctx.send(
            f"{author.mention}, Создал тест!\n{name}",
            components=[
                SelectMenu(
                    custom_id="t1",
                    placeholder="Выбери правильный ответ!",
                    max_values=2,
                    options=[
                        SelectOption(f"{correct}", "Ей"),
                        SelectOption(f"{b}", "Йе")
                    ]
                )
            ]
        )
        inter = await msg.wait_for_dropdown()
     
        labels = [option.label for option in inter.select_menu.selected_options]

        if len(labels) > 1:
            #Вот здесь надо отправить человеку в лс что надо выбрать один ответ

        elif correct in labels:
            #Вот здесь надо отправить тому кто выбрал правильный ответ в лс что он молодец!

        else:
            #Вот здесь надо отправить тому кто выбрал неправильный ответ в лс то что он ответил неправильно
    ...

And still it is necessary to make so that this menu was reusable. So that one person chooses and the other can then choose.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-01-16
@Vindicar

Well, for starters, it would be nice to divide the task into parts, right?
A separate command for creating a test, which can be called not in the general channel (otherwise everyone will immediately understand the correct answer, it is always the first one for you).
A separate command to show the test, if required.
And separate response handlers.
Plus, you need to remember in the bot not only questions, but also which of the users answered how - this will allow you to understand in which case you can ignore the answer, since one answer has already been given.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question