S
S
szjyakgf2021-12-06 21:29:13
Python
szjyakgf, 2021-12-06 21:29:13

How to set the time of the mute, ban in the team?

There is a code when the bot stirs up a person for 5 minutes

@dp.message_handler(commands=['mute'])
async def mute(message: types.Message):
    await message.bot.restrict_chat_member(message.chat.id, message.reply_to_message.from_user.id, until_date=time()+300)

And I need the user to set the mute time (/ mute 3 - which means that you need to mute the user for 3 hours)
number = message.get_args() * 3600 #нужно передать в until_date=time()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-12-06
@Vindicar

get_args() → Optional[str]
According to the documentation, get_args() returns the string that comes after the command, or None. Parsing this line is your concern. For example, like this:
1. assign the result of .get_args() to a variable and make sure it's not None.
2. strip spaces with .strip()
3. turn into int()/ float() and catch an exception if the string is not a number
4. use the resulting value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question