T
T
Telmor2021-09-20 17:47:40
Python
Telmor, 2021-09-20 17:47:40

How to accept an argument to a command after using it in discord.py?

I have a code (below) and I want a person to write a command (let's say !test1) with no arguments. And after pressing the button, the bot prompted him to enter an id or a mention of a person (in a separate message). And having accepted this id, he did the same actions with this person if I wrote the command: !test1 .

The code:

@bot.command()
async def test1(ctx):
    emb = discord.Embed(title='Принятие', descriptione='Здесь принимается id учасника')
    emb.set_thumbnail(url=ctx.author.avatar_url)
    msg = await ctx.send(embed = emb, 
        components = [
            Button(style = ButtonStyle.gray, label='Выдать Роль'),
            Button(style = ButtonStyle.gray, label='Убрать Роль')
        ])
    responce = await bot.wait_for('button_click', check=lambda message: message.author == ctx.author)
    if responce.component.label == 'Выдать Роль':
        emb = discord.Embed(title='Принятие', descriptione='Здесь принимается id роли')
        emb.set_thumbnail(url=ctx.author.avatar_url)
    if responce.component.label == 'Убрать Роль':
        return


Can you help with my question with an example of my or another code?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2021-09-20
@Vindicar

It's impractical.
You need to store for each user the command that he is currently executing, store the step (argument number) on which he is now, and store the previously entered data.
And then when receiving a message:
1. check if the message is a command, if it is, process it separately.
2. determine which processing step of which command is currently active for this user
3. interpret the entered message accordingly.

M
Maxim Nevzorov, 2021-09-20
@fixator10

Just like you get an action from a button:

message = await bot.wait_for('message', check=lambda message: message.author == ctx.author and message.channel == ctx.channel) # получаем сообщение от автора команды в исходном канале
role = await commands.RoleConverter().convert(ctx, message.content)  # получаем роль через конвертер
await ctx.send(role.name)  # показываем имя роли в чате
7jNXvr1.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question