getBotById

The getBotById method retrieves a bot instance based on its unique ID. This method is applicable only for configurations of type "multi".

Method getBotById

Usage:

const bot = multiBotInstance.getBotById(id);

Parameters:

  • id (number): The unique ID of the bot you want to retrieve.

Returns:

  • {TelegramBot|undefined}: Returns the Telegram bot instance if found, or undefined if no bot with the specified ID exists.

Example:

const bot = multiBotInstance.getBotById(1234567890);
if (bot) {
    bot.sendMessage(chatId, 'Hello!');
} else {
    console.log('Bot not found.');
}

Notes:

  • This method is only available for configurations where type is "multi". If the type is "one", this method will not function as intended.

  • Ensure that the bot ID is valid and that the bot has been initialized.

  • The method relies on the global manager's state, so make sure bots are properly loaded and managed.

Last updated