-
Notifications
You must be signed in to change notification settings - Fork 5
Core
This module is the starting point for your Discord SDK application, and contains the Core class which is required to access the other modules.
Discord.Result
A result of a callback, event or function.
-
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 anapplication_id
in yourupdate_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 withfilter()
. -
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.
Discord.CreateFlags
Enum for the Discord Core's creation flags.
0: DEFAULT
1: NO_REQUIRE_DISCORD
Discord.LogLevel
Enum for a Discord debug log's level.
1: ERROR
2: WARN
3: INFO
4: DEBUG
Discord.Core
Extends Reference
.
The core of the SDK, controls all callbacks and managers.
create(app_id: int, create_flags: Discord.CreateFlags, [instance_id: int]) -> Discord.Result
Initialises the Core.
-
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 returnDiscord.Result.INTERNAL_ERROR
if Discord is not running.
-
-
instance_id: int
- The Discord client instance to use. Useful for testing with multiple clients.Default:
None
Discord.Result
- The result from the command.
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_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!
-
min_level: Discord.LogLevel
- The minimum logging level to output.
-
hook_target: Object
- The hook target.hook_method: String
- The hook method's name.log_hook(level: Discord.LogLevel, message: String)
Discord.Result
- The result of the command, will always return INVALID_COMMAND
if Create
has not yet been called.
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() -> Discord.Result
Runs any callbacks, it is recommended to put this in _process
.
Discord.Result
- The result of the command, will always return INVALID_COMMAND
if Create
has not yet been called.
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() -> Discord.UserManager
Gets the User Manager for this Discord instance.
Discord.UserManager
- The corresponding User Manager.
var discord: Discord.Core
var users: Discord.UserManager
func _ready() -> void:
# ...
users = discord.get_user_manager()
get_image_manager() -> Discord.ImageManager
Gets the Image Manager for this Discord instance.
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() -> Discord.ActivityManager
Gets the Activity Manager for this Discord instance.
Discord.ActivityManager
- The corresponding Activity Manager.
var discord: Discord.Core
var activities: Discord.ActivityManager
func _ready() -> void:
# ...
activities = discord.get_activity_manager()
get_relationship_manager() -> Discord.RelationshipManager
Gets the Relationship Manager for this Discord instance.
Discord.RelationshipManager
- The corresponding Relationship Manager.
var discord: Discord.Core
var relationships: Discord.RelationshipManager
func _ready() -> void:
# ...
relationships = discord.get_relationship_manager()
get_network_manager() -> Discord.NetworkManager
Gets the Network Manager for this Discord instance.
Discord.NetworkManager
- The corresponding Network Manager.
var discord: Discord.Core
var networking: Discord.NetworkManager
func _ready() -> void:
# ...
networking = discord.get_network_manager()
log_hook(level: Discord.Result, message: String)
Alternative to the object & method args of set_log_hook
.
-
level: Discord.LogLevel
- The level of the log event. -
message: String
- The log message.