Activities - LennyPhoenix/GodotDiscordSDK GitHub Wiki
This module (and its corresponding manager) helps you to manage Rich Presence and Activities for your game on Discord, allowing other users on Discord to see what they are doing in game.
Contents
- Activity Type (Enum)
- Activity Action Type (Enum)
- Activity Join Request Reply (Enum)
- Activity Timestamps
- Activity Assets
- Party Size
- Activity Party
- Activity Secrets
- Activity
- Activity Manager
Activity Type (Enum)
Discord.ActivityType
Description
Enum for the different type of activities.
Items
0: PLAYING
1: STREAMING
2: LISTENING
3: WATCHING
Activity Action Type (Enum)
Discord.ActivityActionType
Description
Enum for the different types of activity actions.
Items
1: JOIN
2: SPECTATE
[Deprecated]
Activity Join Request Reply (Enum)
Discord.ActivityJoinRequestReply
Description
Enum for the different types of request reply.
Items
0: NO
1: YES
2: IGNORE
Activity Timestamps
Discord.ActivityTimestamps
Extends Resource
.
Description
Stores timestamp info for an activity.
Properties
Start
start: int
The starting unix timestamp of the activity. Set to have an "elapsed" timer.
Default: 0
End
end: int
The ending unix timestamp of the activity. Set to have a "remaining" timer.
Default: 0
Activity Assets
Discord.ActivityAssets
Extends Resource
.
Description
Stores asset info for an activity.
Properties
Large Image
large_image: String
The keyname of the large asset of an activity, limited to 127 characters.
Default: ""
Large Text
large_text: String
The hover text for the large image of an activity, limited to 127 characters.
Default: ""
Small Image
small_image: String
The keyname of the small asset of an activity, limited to 127 characters.
Default: ""
Small Text
small_text: String
The hover text for the small image of an activity, limited to 127 characters.
Default: ""
Party Size
Discord.PartySize
Extends Resource
.
Description
Stores info about the size of a party.
Properties
Current Size
current_size: int
The current size of the party, a 32-bit integer.
Default: 0
Max Size
max_size: int
The maximum size of the party, a 32-bit integer.
Default: 0
Activity Party
Discord.ActivityParty
Extends Resource
.
Description
Stores information about the activity party.
Properties
ID
id: String
The unique part ID, limited to 127 characters.
Default: ""
Size
size: Discord.PartySize
The size data for a party.
Default: new Discord.PartySize
(Will appear as [empty]
in the editor due to current limitations.)
Activity Secrets
Discord.ActivitySecrets
Extends Resource
.
Description
Contains secret passwords for joining and spectating a game.
Properties
Match
match: String
A unique hash for the given match context, limited to 127 characters. [Unused]
Default: ""
Join
join: String
A unique hash for chat invites and Ask to Join, limited to 127 characters. Required for the Join or Ask To Join button to be visible.
Default: ""
Spectate
spectate: String
A unique hash for spectating, limited to 127 characters.
Required for the Spectate button to be visible.
[Deprecated]
Default: ""
Activity
Discord.Activity
Extends Resource
.
Description
Contains data for an activity to display on your Discord profile.
Properties
Application ID
application_id: int
Your application identifier. This is a read-only field.
Default: 0
Name
name: String
The name of the application, limited to 127 characters. This is a read-only field.
Default: ""
State
state: String
The player's current party status, limited to 127 characters.
Default: ""
Details
details: String
What the player is currently doing, limited to 127 characters.
Default: ""
Timestamps
timestamps: Discord.ActivityTimestamps
Helps create elapsed/remaining timestamps on a player's activity.
Default: new Discord.ActivityTimestamps
(Will appear as [empty]
in the editor due to current limitations.)
Assets
assets: Discord.ActivityAssets
Assets to display on the player's activity.
Default: new Discord.ActivityAssets
(Will appear as [empty]
in the editor due to current limitations.)
Party
party: Discord.ActivityParty
Information about the player's party.
Default: new Discord.ActivityParty
(Will appear as [empty]
in the editor due to current limitations.)
Secrets
secrets: Discord.ActivitySecrets
Secret passwords for joining and spectating the player's game.
Default: new Discord.ActivitySecrets
(Will appear as [empty]
in the editor due to current limitations.)
Instance
instance: bool
Whether this activity is an instanced context, like a match. [Unused]
Default: false
Activity Manager
Discord.ActivityManager
Extends Object
.
Description
Contains methods and events related to activities.
Methods
Register Command
register_command(command: String) -> Discord.Result
Registers a command by which Discord can launch your game. This might be a custom protocol, like my-awesome-game://
, or a path to an executable. It also supports any launch parameters that may be needed, like game.exe --full-screen --no-hax
.
On macOS, due to the way Discord registers executables, your game needs to be bundled for this command to work. That means it should be a .app
.
Arguments
command: String
- The command to register.
Returns
Discord.Result
- The result of the operation.
Example
var discord: Discord.Core
var activities: Discord.ActivityManager
func _ready() -> void:
# ...
activities.register_command(OS.get_executable_path())
Register Steam
register_steam(steam_id: int) -> Discord.Result
Used if you are distributing this SDK on Steam. Registers your game's Steam app id for the protocol steam://run-game-id/<id>
.
Arguments
steam_id: int
- Your game's Steam app id.
Returns
Discord.Result
- The result of the operation.
Example
var discord: Discord.Core
var activities: Discord.ActivityManager
func _ready() -> void:
# ...
activities.register_steam(INSERT_STEAM_ID)
Update Activity
update_activity(activity: Discord.Activity, [callback_target: Object, callback_method: String]) -> void
Updates the user's displayed activity, and returns the success via a callback.
Has a corresponding signal update_activity_callback
that can be used instead of the optional target & method args.
Arguments
activity: Discord.Activity
- The new activity for the user.
Optional Args
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.update_activity_callback(result: Discord.Result)
Example
var discord: Discord.Core
var activities: Discord.ActivityManager
func _ready() -> void:
# ...
var activity: = Discord.Activity.new()
activity.state = "Testing..."
activity.details = "Still testing..."
activity.timestamps.start = OS.get_unix_time()
activity.assets.large_image = "icon"
activity.assets.large_text = "Powered by the GodotDiscordSDK"
activities.update_activity(activity, self, "_update_activity_callback")
func _update_activity_callback(result: int) -> void:
if result != Discord.Result.OK:
print("Failed to update activity: ", result)
return
print("Successfully updated the current activity!")
Clear Activity
clear_activity([callback_target: Object, callback_method: String]) -> void
Clears the user's current activity RPC.
Has a corresponding signal clear_activity_callback
that can be used instead of the optional target & method args.
Optional Args
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.clear_activity_callback(result: Discord.Result)
Example
var discord: Discord.Core
var activities: Discord.ActivityManager
func _ready() -> void:
# ...
activities.clear_activity(self, "_clear_activity_callback")
func _clear_activity_callback(result: int) -> void:
if result != Discord.Result.OK:
print("Failed to clear activity: ", result)
return
print("Successfully cleared the current activity!")
Send Request Reply
send_request_reply(user_id: int, reply: Discord.ActivityJoinRequestReply, [callback_target: Object, callback_method: String]) -> void
Sends a reply to an Ask to Join request.
Has a corresponding signal send_request_reply_callback
that can be used instead of the optional target & method args.
Arguments
-
user_id: int
- The user ID of the person who asked to join. -
reply: Discord.ActivityJoinRequestReply
- The response to send:No
,Yes
, orIgnore
.
Optional Args
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.send_request_reply_callback(result: Discord.Result)
Example
var discord: Discord.Core
var activities: Discord.ActivityManager
func _ready() -> void:
# ...
activities.connect(
"activity_join_request",
self, "_on_activity_join_request"
)
func _on_activity_join_request(user: Discord.User) -> void:
print(
"Received join request from @",
user.username, "#", user.discriminator
)
activities.send_request_reply(
user.id, Discord.ActivityJoinRequestReply.YES,
self, "_send_request_reply_callback"
)
func _send_request_reply_callback(result: int) -> void:
if result != Discord.Result.OK:
print("Failed to send request reply: ", result)
print("Successfully accepted activity join request.")
Send Invite
send_invite(user_id: int, type: Discord.ActivityActionType, content: String, [callback_target: Object, callback_method: String]) -> void
Sends a game invite to a given user. If you do not have a valid activity with all the required fields, this call will error. See Activity Action Field Requirements for the fields required to have join and spectate invites function properly.
Has a corresponding signal send_invite_callback
that can be used instead of the optional target & method args.
Arguments
-
user_id: int
- The user ID of the person to invite. -
type: Discord.ActivityActionType
- This marks the invite as an invitation to join orspectate. -
content: String
- A message to send along with the invite.
Optional Args
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.send_invite_callback(result: Discord.Result)
Example
var discord: Discord.Core
var activities: Discord.ActivityManager
func _ready() -> void:
# ...
var activity: = Discord.Activity.new()
# ...
activity.party.id = "PARTY_ID"
activity.secrets.join = "SUPER_SECRET_VALUE"
activity.party.size.current_size = 1
activity.party.size.max_size = 2
activities.update_activity(
activity,
self, "_update_activity_callback"
)
func _update_activity_callback(result: int) -> void:
if result != Discord.Result.OK:
print("Failed to update activity: ", result)
return
activities.send_invite(
425340416531890178, "Here is an activity invite:",
self, "_send_invite_callback"
)
func _send_invite_callback(result: int) -> void:
if result != Discord.Result.OK:
print("Failed to send invite: ", result)
print("Successfully sent activity invite.")
Accept Invite
accept_invite(user_id: int, [callback_target: Object, callback_method: String]) -> void
Accepts a game invitation from a given user ID.
Has a corresponding signal accept_invite_callback
that can be used instead of the optional target & method args.
Arguments
user_id: int
- The ID of the user who invited you.
Optional Args
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.accept_invite_callback(result: Discord.Result)
Example
var discord: Discord.Core
var activities: Discord.ActivityManager
func _ready() -> void:
# ...
activities.connect(
"acivity_invite",
self, "_on_activity_invite"
)
func _on_activity_invite(type: int, user: Discord.User, activity: Discord.Activity) -> void:
activities.accept_invite(
user.id,
self, "_accept_invite_callback"
)
func _accept_invite_callback(result: int) -> void:
if result != Discord.Result.OK:
print("Failed to accept invite: ", result)
print("Successfully accepted activity invite.")
Signals
Activity Join
activity_join(join_secret: String)
Fires when a user accepts a game chat invite or receives confirmation from Asking to Join.
Arguments
join_secret: String
- The secret to join the user's game.
Example
var discord: Discord.Core
var activities: Discord.ActivityManager
func _ready() -> void:
# ...
activities.connect(
"acivity_join",
self, "_on_activity_join"
)
func _on_activity_join(join_secret: String) -> void:
print("Successfully joined activity with join secret: ", join_secret)
Activity Spectate
activity_spectate(spectate_secret: String)
Fires when a user accepts a spectate chat invite or clicks the Spectate button on a user's profile.
[Deprecated]
Arguments
spectate_secret: String
- The secret to join the user's game as a spectator.
Example
var discord: Discord.Core
var activities: Discord.ActivityManager
func _ready() -> void:
# ...
activities.connect(
"acivity_spectate",
self, "_on_activity_spectate"
)
func _on_activity_spectate(spectate_secret: String) -> void:
print("Successfully spectated activity with spectate secret: ", join_secret)
Activity Join Request
activity_join_request(user: Discord.User)
Fires when a user asks to join the current user's game.
Arguments
user: Discord.User
- The user asking to join.
Example
var discord: Discord.Core
var activities: Discord.ActivityManager
func _ready() -> void:
# ...
activities.connect(
"activity_join_request",
self, "_on_activity_join_request"
)
func _on_activity_join_request(user: Discord.User) -> void:
print(
"Received join request from @",
user.username, "#", user.discriminator
)
Activity Invite
activity_invite(type: Discord.ActivityActionType, user: Discord.User, activity: Discord.Activity)
Fires when the user receives a join or spectate invite.
Arguments
-
type: Discord.ActivityActionType
- Whether this invite is to join orspectate. -
user: Discord.User
- The user asking to join. -
activity: Discord.Activity
- The inviting user's current activity.
Example
var discord: Discord.Core
var activities: Discord.ActivityManager
func _ready() -> void:
# ...
activities.connect(
"acivity_invite",
self, "_on_activity_invite"
)
func _on_activity_invite(type: int, user: Discord.User, activity: Discord.Activity) -> void:
print(
"Received activity invite for ", activity.name, " from @",
user.username, "#", user.discriminator
)
Update Activity (Callback)
update_activity_callback(result: Discord.Result)
Alternative to the object & method args of update_activity
.
Arguments
result: Discord.Result
- The result of the command.
Clear Activity (Callback)
clear_activity_callback(result: Discord.Result)
Alternative to the object & method args of clear_activity
.
Arguments
result: Discord.Result
- The result of the command.
Send Request Reply (Callback)
send_request_reply_callback(result: Discord.Result)
Alternative to the object & method args of send_request_reply
.
Arguments
result: Discord.Result
- The result of the command.
Send Invite (Callback)
send_invite_callback(result: Discord.Result)
Alternative to the object & method args of send_invite
.
Arguments
result: Discord.Result
- The result of the command.
Accept Invite (Callback)
accept_invite_callback(result: Discord.Result)
Alternative to the object & method args of accept_invite
.
Arguments
result: Discord.Result
- The result of the command.