Runtime API
RuntimeOn this page
Built-in modules: require("runtime"), require("http"), require("json").
runtime
runtime.log
Signature
runtime.log(level, module, message)Write a log line through the native runtime logger.
| Name | Type | Required | Behavior |
|---|---|---|---|
level |
any |
required | Passed through to the implementation as written. |
module |
any |
required | Passed through to the implementation as written. |
message |
any |
required | Passed through to the implementation as written. |
runtime.setTimeout
Signature
runtime.setTimeout(ms, callback)Schedule a one-shot timer. Returns a timer id.
| Name | Type | Required | Behavior |
|---|---|---|---|
ms |
number |
required | Duration in milliseconds. |
callback |
function |
optional | Optional completion callback function(err, result). If omitted, failures raise a DiscordLua error. |
runtime.setInterval
Signature
runtime.setInterval(ms, callback)Schedule a repeating timer. Returns a timer id.
| Name | Type | Required | Behavior |
|---|---|---|---|
ms |
number |
required | Duration in milliseconds. |
callback |
function |
optional | Optional completion callback function(err, result). If omitted, failures raise a DiscordLua error. |
runtime.clearTimer
Signature
runtime.clearTimer(id)Cancel a timer previously returned by setTimeout or setInterval.
| Name | Type | Required | Behavior |
|---|---|---|---|
id |
string |
required | Snowflake id string. |
runtime.stop
Signature
runtime.stop()Stop the native event loop so the process can exit cleanly.
No parameters.
runtime.spawn
Signature
runtime.spawn(fn)Start child processes or shards.
| Name | Type | Required | Behavior |
|---|---|---|---|
fn |
any |
required | Passed through to the implementation as written. |
runtime.readFile
Signature
runtime.readFile(path)Read a UTF-8 text file from disk and return its contents.
| Name | Type | Required | Behavior |
|---|---|---|---|
path |
any |
required | Passed through to the implementation as written. |
runtime.exePath
Signature
runtime.exePath()Return the absolute path of the running dislua executable.
No parameters.
runtime.spawnProcess
Signature
runtime.spawnProcess(file, args, options)Spawn a child process. ShardingManager uses this to launch shard workers.
| Name | Type | Required | Behavior |
|---|---|---|---|
file |
any |
required | Passed through to the implementation as written. |
args |
any |
required | Passed through to the implementation as written. |
options |
table |
optional | Lua option table. Field names match the corresponding DiscordLua option type when one exists. |
runtime.writeStdout
Signature
runtime.writeStdout(text)Write a string to standard output without adding a Lua print prefix.
| Name | Type | Required | Behavior |
|---|---|---|---|
text |
any |
required | Passed through to the implementation as written. |
runtime.listenStdin
Signature
runtime.listenStdin(callback)Register a callback that receives lines from standard input.
| Name | Type | Required | Behavior |
|---|---|---|---|
callback |
function |
optional | Optional completion callback function(err, result). If omitted, failures raise a DiscordLua error. |
http.request
http.request(options, callback)Options: method, url, headers, body. Callback receives (err, response) with status, body, headers.
json
json.encode(value) and json.decode(text).
Internal require("_discord") is the native handle used by the Discord module. Bot scripts should use require("discord").