BJS errors and debugging
Diagnose BJS errors by command and context, fix common callback and method mistakes, and customize the private-chat error response with the ! command.
Start with the failed command and its error message. A syntax error, missing context, unsupported method, failed external request, and exhausted execution limit require different fixes.
A useful debugging sequence
Reproduce the command on a test bot with a specific message or button action.
Open the bot's Errors screen and inspect the latest relevant entry.
Check the named command and code location, then identify its trigger and required variables.
Reduce the example to one action. Add the next step only after the first works.
Repeat the original flow, including callbacks and a later read when data persistence matters.
Use the app guide for finding an error and its command.
Inspect only the values you need
// Temporary diagnostic command on a test bot.
Bot.inspect({
has_user: !!user,
has_chat: !!chat,
parameters: (params || "").slice(0, 100),
option_keys: options ? Object.keys(options) : []
});Do not print the entire bot, owner, request headers, account response, or credential-bearing panel. Remove temporary diagnostics when the issue is understood.
Common problems
Method is not defined
Exact object/method spelling: HTTP, Api, AdminPanel.getFieldValue; a method copied from ordinary JavaScript may not exist in BJS
User.getProp reports user is not defined (the error may name User.getProperty)
The trigger has no current user; check context and explicit scope
Cannot read a property of undefined/null
Guard the parent object; a manually invoked callback has no remote result
HTTP JSON parse error
Check status and body format before JSON.parse(content)
API callback does not run
Saved callback command name, on_result vs HTTP success, backend method support, and error callback
“Too many sub commands”
Recursive or overly long command/callback chains; split work into bounded steps
Timeout
Unbounded loops, repeated requests, expensive data loading, or execution limits
Property changed immediately but not in the next command
Verify write scope, persisted type, later read, and false-like default behavior
New defaults did not replace panel values
Admin Panel preserves old values unless intentionally forced
A JavaScript try/catch handles errors thrown while that BJS code runs. It does not turn a queued remote request into a synchronous operation. Use HTTP success/error commands or Api result/error commands for remote outcomes.
Make examples easier to maintain
Use named variables, small functions, clear guards, and one purpose per command. Keep a local function in the command that calls it. To reuse complex validation across commands, see custom libraries; check the helper's execution context and return behavior before sharing it. Keep callback names and their handlers together in the article or project.
For a bot that never reaches the command at all, use Bot not responding. For an execution problem, start with BJS context and the relevant method reference.
Last updated
Was this helpful?