Skip to content
dekkonot edited this page Jun 18, 2019 · 4 revisions

Discordia Function Returning

Discordia uses a success, value system. Most api methods like say message:delete() would return boolean[, errmsg]
This first return value is success and should alway be a boolean value, if success == false then an error message will be provided as the second return value

Selective Erroring

Using assert() and pcall()

With the first return value being success on discordia methods assert(message:delete(), 'Failed to delete message') would work without error. While pcall attempts to call and catch an error the first return value for pcall(function() return message:delete() end) would be the pcall's success with all discordia returns following that

assert(message:delete())

Will error if the method fails

pcall(function() return message:delete() end)

Should always return success
Returns

  • pcall success
  • method success
  • method return or error message

Discordia Logging

logLevel.debug [4]

Will log events such as identify http requests, all shard receive events, and your Gateway Sequence

logLevel.info [3]

Will log events such as authenticating your bot, connecting to the gateway, launching shards, and receiving READY from the Discord Gateway

logLevel.warning [2]

Will log events such as Uncached and Unhandled Gateway Events, Unacknowledged Gateway heartbeats, Requesting reconnections

logLevel.error [1]

Will log events such as API request failures, Sharding errors, failure to retrieve: the Discord Gateway, Application Information, Proper authentication

logLevel.none [0]

Will log absolutely NOTHING

Custom Logging

Defining Logger

local discordia = require('discordia')
local logger = discordia.Logger(3, '%F %T')

Initilizing Logger

local logger = discordia.Logger(logLevel, dateTime[, fileName])

Initilization Options

  • logLevel: number
  • dateTime: string
  • fileName: string

See above for human readable logLevels

Methods

string log(logLevel, msg[, ...])

  • logLevel: number
  • msg: string
  • ...: * Events logged to logLevels above the initilized number will be ignored.
    msg will be formatted via string.format(msg, ...)
Clone this wiki locally