NxCreateDocs

Python: libs Reference

Counters, random values, date/time, webhook URLs, and regex.

libs is a collection of small utilities for common bot tasks.

Resources — counters

Numeric counters, either bot-wide, per-user, or for a specific user.

libs.Resources.globalRes('total_orders').add(1)
libs.Resources.userRes('points').set(100)
libs.Resources.anotherRes('points', user=other_chat_id).cut(10)

current = libs.Resources.userRes('points').value()
MethodScope
globalRes(key)Bot-wide counter.
userRes(key)Current user’s counter.
anotherRes(key, user=None)A specific user’s counter.

Each returns an object with .value(), .add(n), .cut(n), and .set(v).

Random values

code = libs.Random.randomStr(8, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
roll = libs.Random.randomInt(1, 6)
prize = libs.random.randomWeightedChoice(['gold', 'silver', 'bronze'], [1, 3, 6])

Date & time

now = libs.DateAndTime.now('Asia/Kolkata')
print(now.strftime('%Y-%m-%d %H:%M'))

Webhook URLs

Build a URL that routes back into your bot — useful for payment callbacks or external services that need to reach a specific command.

url = libs.webhook.getUrlFor(command='/payment_confirmed', user_id=u)

Regex

The standard Python re module, available as libs.re.

digits = libs.re.sub(r'[^0-9]', '', text)
Last updated August 11, 2026
Was this page helpful?