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

Method add

telebot/types.py:2766–2803  ·  view source on GitHub ↗

This function adds strings to the keyboard, while not exceeding row_width. E.g. ReplyKeyboardMarkup#add("A", "B", "C") yields the json result {keyboard: [["A"], ["B"], ["C"]]} when row_width is set to 1. When row_width is set to 2, the following is the result of this

(self, *args, row_width=None)

Source from the content-addressed store, hash-verified

2764 self.is_persistent: Optional[bool] = is_persistent
2765
2766 def add(self, *args, row_width=None) -> 'ReplyKeyboardMarkup':
2767 """
2768 This function adds strings to the keyboard, while not exceeding row_width.
2769 E.g. ReplyKeyboardMarkup#add("A", "B", "C") yields the json result {keyboard: [["A"], ["B"], ["C"]]}
2770 when row_width is set to 1.
2771 When row_width is set to 2, the following is the result of this function: {keyboard: [["A", "B"], ["C"]]}
2772 See https://core.telegram.org/bots/api#replykeyboardmarkup
2773
2774 :param args: KeyboardButton to append to the keyboard
2775 :type args: :obj:`str` or :class:`telebot.types.KeyboardButton`
2776
2777 :param row_width: width of row
2778 :type row_width: :obj:`int`
2779
2780 :return: self, to allow function chaining.
2781 :rtype: :class:`telebot.types.ReplyKeyboardMarkup`
2782 """
2783 if row_width is None:
2784 row_width = self.row_width
2785
2786 if row_width > self.max_row_keys:
2787 # Todo: Will be replaced with Exception in future releases
2788 if not DISABLE_KEYLEN_ERROR:
2789 logger.error('Telegram does not support reply keyboard row width over %d.' % self.max_row_keys)
2790 row_width = self.max_row_keys
2791
2792 for row in service_utils.chunks(args, row_width):
2793 button_array = []
2794 for button in row:
2795 if service_utils.is_string(button):
2796 button_array.append({'text': button})
2797 elif service_utils.is_bytes(button):
2798 button_array.append({'text': button.decode('utf-8')})
2799 else:
2800 button_array.append(button.to_dict())
2801 self.keyboard.append(button_array)
2802
2803 return self
2804
2805 def row(self, *args) -> 'ReplyKeyboardMarkup':
2806 """

Callers 13

send_welcomeFunction · 0.95
keyboardFunction · 0.95
process_age_stepFunction · 0.95
ask_colorFunction · 0.95
ask_hobbyFunction · 0.95
menu_keyboardFunction · 0.95
ask_colorFunction · 0.95
ask_hobbyFunction · 0.95
menu_keyboardFunction · 0.95

Calls 1

to_dictMethod · 0.45