discord_config_init - create a Discord client handle from a config file#

struct discord *discord_config_init(const char config_file[])#

Create a Discord Client handle by a bot.config file.

Parameters:
  • config_file – the bot.config file name

Returns:

the newly created Discord Client handle

Sample config.json#

{
  "logging": {
    "level": "trace",
    "filename": "bot.log",
    "quiet": false,
    "overwrite": true,
    "use_color": true,
    "http": {
      "enable": true,
      "filename": "http.log"
    },
    "disable_modules": [
      "WEBSOCKETS",
      "USER_AGENT",
      "DISCORD_HTTP",
    ]
  },
  "discord": {
    "token": "YOUR-BOT-TOKEN",
    "default_prefix": {
      "enable": true,
      "prefix": "!"
    }
  }
}

Example#

void on_ready(struct discord *client)
{
  log_info("Up and running!");
}

int main(void)
{
  struct discord *client = discord_config_init("config.json");
  discord_set_on_ready(client, &on_ready);
  discord_run(client);
  discord_cleanup(client);
}