MCPcopy Create free account
hub / github.com/eternnoir/pyTelegramBotAPI / set

Method set

telebot/states/asyncio/context.py:29–56  ·  view source on GitHub ↗

Set state for current user. :param state: State object or state name. :type state: Union[State, str] .. code-block:: python3 @bot.message_handler(commands=['start']) async def start_ex(message: types.Message, state_context: StateContext):

(self, state: Union[State, str])

Source from the content-addressed store, hash-verified

27 self.bot_id = self.bot.bot_id
28
29 async def set(self, state: Union[State, str]) -> bool:
30 """
31 Set state for current user.
32
33 :param state: State object or state name.
34 :type state: Union[State, str]
35
36 .. code-block:: python3
37
38 @bot.message_handler(commands=['start'])
39 async def start_ex(message: types.Message, state_context: StateContext):
40 await state_context.set(MyStates.name)
41 await bot.send_message(message.chat.id, 'Hi, write me a name', reply_to_message_id=message.message_id)
42 """
43
44 chat_id, user_id, business_connection_id, bot_id, message_thread_id = (
45 resolve_context(self.message, self.bot.bot_id)
46 )
47 if isinstance(state, State):
48 state = state.name
49 return await self.bot.set_state(
50 chat_id=chat_id,
51 user_id=user_id,
52 state=state,
53 business_connection_id=business_connection_id,
54 bot_id=bot_id,
55 message_thread_id=message_thread_id,
56 )
57
58 async def get(self) -> str:
59 """

Callers

nothing calls this directly

Calls 2

resolve_contextFunction · 0.90
set_stateMethod · 0.45

Tested by

no test coverage detected