Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.
LennyPhoenix edited this page Jun 2, 2021 · 25 revisions

This module is the starting point for your Discord SDK application, and contains the Core class which is required to access the other modules.

Contents

Result (Enum)

Discord.Result

Description

A result of a callback, event or function.

Items

  • 0: OK - Everything is good.
  • 1: SERVICE_UNAVAILABLE - Discord isn't working.
  • 2: INVALID_VERSION - The SDK version may be outdated.
  • 3: LOCK_FAILED - An internal error on transactional operations.
  • 4: INTERNAL_ERROR - Something on our side went wrong.
  • 5: INVALID_PAYLOAD - The data you sent didn't match what we expected.
  • 6: INVALID_COMMAND - That's not a thing you can do.
  • 7: INVALID_PERMISSIONS - You aren't authorized to do that.
  • 8: NOT_FETCHED - Couldn't fetch what you wanted.
  • 9: NOT_FOUND - What you're looking for doesn't exist.
  • 10: CONFLICT - User already has a network connection open on that channel.
  • 11: INVALID_SECRET - Activity secrets must be unique and not match party ID.
  • 12: INVALID_JOIN_SECRET - Join request for that user does not exist.
  • 13: NO_ELIGIBLE_ACTIVITY - You accidentally set an application_id in your update_activity() payload.
  • 14: INVALID_INVITE - Your game invite is no longer valid.
  • 15: NOT_AUTENTICATED - The internal auth call failed for the user, and you can't do this.
  • 16: INVALID_ACCESS_TOKEN - The user's bearer token is invalid.
  • 17: APPLICATION_MISMATCH - Access token belongs to another application.
  • 18: INVALID_DATA_URL - Something internally went wrong fetching image data.
  • 19: INVALID_BASE_64 - Not valid Base64 data.
  • 20: NOT_FILTERED - You're trying to access the list before creating a stable list with filter().
  • 21: LOBBY_FULL - The lobby full.
  • 22: INVALID_LOBBY_SECRET - The secret you're using to connect is wrong.
  • 23: INVALID_FILENAME - File name is too long.
  • 24: INVALID_FILE_SIZE - File is too large.
  • 25: INVALID_ENTITLEMENT - The user does not have the right entitlement for this game.
  • 26: NOT_INSTALLED - Discord is not installed.
  • 27: NOT_RUNNING - Discord is not running.
  • 28: INSUFFICIENT_BUFFER - Insufficient buffer space when trying to write.
  • 29: PURCHASE_CANCELLED - User cancelled the purchase flow.
  • 30: INVALID_GUILD - Discord guild does not exist.
  • 31: INVALID_EVENT - The event you're trying to subscribe to does not exist.
  • 32: INVALID_CHANNEL - Discord channel does not exist.
  • 33: INVALID_ORIGIN - The origin header on the socket does not match what you've registered.
  • 34: RATE_LIMITED - You are calling that method too quickly.
  • 35: OAUTH2_ERROR - The OAuth2 process failed at some point.
  • 36: SELECT_CHANNEL_TIMEOUT - The user took too long selecting a channel for an invite.
  • 37: GET_GUILD_TIMEOUT - Took too long trying to fetch the guild.
  • 38: SELECT_VOID_FORCE_REQUIRED - Push to talk is required for this channel.
  • 39: CAPTURE_SHORTCUT_ALREADY_LISTENING - That push to talk shortcut is already registered.
  • 40: UNAUTHORIZED_FOR_ACHIEVEMENT - Your application cannot update this achievement.
  • 41: INVALID_GIFT_CODE - The gift code is not valid.
  • 42: PURCHASE_ERROR - Something went wrong during the purchase flow.
  • 43: TRANSACTION_ABORTED - Purchase flow aborted because the SDK is being torn down.

Create Flags (Enum)

Discord.CreateFlags

Description

Enum for the Discord Core's creation flags.

Items

  • 0: DEFAULT
  • 1: NO_REQUIRE_DISCORD

Log Level (Enum)

Discord.LogLevel

Description

Enum for a Discord debug log's level.

Items

  • 1: ERROR
  • 2: WARN
  • 3: INFO
  • 4: DEBUG

Core

Discord.Core

Extends Reference.

Description

The core of the SDK, controls all callbacks and managers.

Methods

Create

create(app_id: int, create_flags: Discord.CreateFlags, [instance_id: int]) -> Discord.Result

Initialises the Core.

Arguments

  • app_id: int - The Discord application ID.

  • create_flags: Discord.CreateFlags - The flags to create with:

    • Discord.CreateFlags.DEFAULT - Makes sure that Discord is currently running, and if not it will close the app, start Discord then reopen the application.

    • Discord.CreateFlags.NO_REQUIRE_DISCORD - Will return Discord.Result.INTERNAL_ERROR if Discord is not running.

Optional Args

Returns

Discord.Result - The result from the command.

Example

var discord: Discord.Core


func _ready() -> void:
	discord = Discord.Core.new()
	var result: int = discord.create(
		807697044516372541,
		Discord.CreateFlags.DEFAULT
	)

	if result != Discord.Result.OK:
		print(
			"Failed to initialise Discord Core: ",
			result
		)
		discord = null
		return

	print("Initialised core successfully.")

Set Log Hook

set_hook_log(min_level: Discord.LogLevel, [hook_target: Object, hook_method: String]) -> Discord.Result

Registers a logging callback method with the minimum level of message to receive. Has a corresponding signal log_hook that can be used instead of the optional target & method args. This function must be run for the signal to work!

Arguments

  • min_level: Discord.LogLevel - The minimum logging level to output.

Optional Args

  • hook_target: Object - The hook target.

    hook_method: String - The hook method's name.

    log_hook(level: Discord.LogLevel, message: String)

Returns

Discord.Result - The result of the command, will always return INVALID_COMMAND if Create has not yet been called.

Example

var discord: Discord.Core


func _ready() -> void:
	# ...
	discord.set_log_hook(Discord.LogLevel.DEBUG, self, "_log_hook")


func _log_hook(level: int, message: String) -> void:
	print("[DISCORD] ", level, ": ", message)

Run Callbacks

run_callbacks() -> Discord.Result

Runs any callbacks, it is recommended to put this in _process.

Returns

Discord.Result - The result of the command, will always return INVALID_COMMAND if Create has not yet been called.

Example

var discord: Discord.Core


func _process(_delta: float) -> void:
	var result: int = discord.run_callbacks()
	if result != Discord.Result.OK:
		print("Failed to run callbacks, aborting: ", result)
		discord = null

Get User Manager

get_user_manager() -> Discord.UserManager

Gets the User Manager for this Discord instance.

Returns

Discord.UserManager - The corresponding User Manager.

Example

var discord: Discord.Core
var users: Discord.UserManager


func _ready() -> void:
	# ...
	users = discord.get_user_manager()

Get Image Manager

get_image_manager() -> Discord.ImageManager

Gets the Image Manager for this Discord instance.

Returns

Discord.ImageManager - The corresponding Image Manager.

var discord: Discord.Core
var images: Discord.ImageManager


func _ready() -> void:
	# ...
	images = discord.get_image_manager()

Get Activity Manager

get_activity_manager() -> Discord.ActivityManager

Gets the Activity Manager for this Discord instance.

Returns

Discord.ActivityManager - The corresponding Activity Manager.

Example

var discord: Discord.Core
var activities: Discord.ActivityManager


func _ready() -> void:
	# ...
	activities = discord.get_activity_manager()

Get Relationship Manager

get_relationship_manager() -> Discord.RelationshipManager

Gets the Relationship Manager for this Discord instance.

Returns

Discord.RelationshipManager - The corresponding Relationship Manager.

Example

var discord: Discord.Core
var relationships: Discord.RelationshipManager


func _ready() -> void:
	# ...
	relationships = discord.get_relationship_manager()

Get Network Manager

get_network_manager() -> Discord.NetworkManager

Gets the Network Manager for this Discord instance.

Returns

Discord.NetworkManager - The corresponding Network Manager.

Example

var discord: Discord.Core
var networking: Discord.NetworkManager


func _ready() -> void:
	# ...
	networking = discord.get_network_manager()

Signals

Log Hook

log_hook(level: Discord.Result, message: String)

Alternative to the object & method args of set_log_hook.

Arguments

  • level: Discord.LogLevel - The level of the log event.

  • message: String - The log message.