DiscordLua
discorddiscord
v1.2.4
Install

Runtime API

Runtime
On 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.

NameTypeRequiredBehavior
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.

NameTypeRequiredBehavior
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.

NameTypeRequiredBehavior
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.

NameTypeRequiredBehavior
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.

NameTypeRequiredBehavior
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.

NameTypeRequiredBehavior
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.

NameTypeRequiredBehavior
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.

NameTypeRequiredBehavior
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.

NameTypeRequiredBehavior
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").

Search Ctrl K Navigate Open Esc