-
Notifications
You must be signed in to change notification settings - Fork 5
Activities
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.
- 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
Discord.ActivityType
Enum for the different type of activities.
0: PLAYING
1: STREAMING
2: LISTENING
3: WATCHING
Discord.ActivityActionType
Enum for the different types of activity actions.
1: JOIN
-
2: SPECTATE
[Deprecated]
Discord.ActivityJoinRequestReply
Enum for the different types of request reply.
0: NO
1: YES
2: IGNORE
Discord.ActivityTimestamps
Extends Resource
.
Stores timestamp info for an activity.
start: int
The starting unix timestamp of the activity. Set to have an "elapsed" timer.
Default: 0
end: int
The ending unix timestamp of the activity. Set to have a "remaining" timer.
Default: 0
Discord.ActivityAssets
Extends Resource
.
Stores asset info for an activity.
large_image: String
The keyname of the large asset of an activity, limited to 127 characters.
Default: ""
large_text: String
The hover text for the large image of an activity, limited to 127 characters.
Default: ""
small_image: String
The keyname of the small asset of an activity, limited to 127 characters.
Default: ""
small_text: String
The hover text for the small image of an activity, limited to 127 characters.
Default: ""
Discord.PartySize
Extends Resource
.
Stores info about the size of a party.
current_size: int
The current size of the party, a 32-bit integer.
Default: 0
max_size: int
The maximum size of the party, a 32-bit integer.
Default: 0
Discord.ActivityParty
Extends Resource
.
Stores information about the activity party.
id: String
The unique part ID, limited to 127 characters.
Default: ""
size: Discord.PartySize
The size data for a party.
Default: new Discord.PartySize
(Will appear as [empty]
in the editor due to current limitations.)
Discord.ActivitySecrets
Extends Resource
.
Contains secret passwords for joining and spectating a game.
match: String
A unique hash for the given match context, limited to 127 characters. [Unused]
Default: ""
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: String
A unique hash for spectating, limited to 127 characters.
Required for the Spectate button to be visible.
[Deprecated]
Default: ""
Discord.Activity
Extends Resource
.
Contains data for an activity to display on your Discord profile.
application_id: int
Your application identifier. This is a read-only field.
Default: 0
name: String
The name of the application, limited to 127 characters. This is a read-only field.
Default: ""
state: String
The player's current party status, limited to 127 characters.
Default: ""
details: String
What the player is currently doing, limited to 127 characters.
Default: ""
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: 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: Discord.ActivityParty
Information about the player's party.
Default: new Discord.ActivityParty
(Will appear as [empty]
in the editor due to current limitations.)
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: bool
Whether this activity is an instanced context, like a match. [Unused]
Default: false
Discord.ActivityManager
Extends Object
.
Contains methods and events related to activities.
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
.
-
command: String
- The command to register.
Discord.Result
- The result of the operation.
var discord: Discord.Core
var activities: Discord.ActivityManager
func _ready() -> void:
# ...
activities.register_command(OS.get_executable_path())
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>
.
-
steam_id: int
- Your game's Steam app id.
Discord.Result
- The result of the operation.
var discord: Discord.Core
var activities: Discord.ActivityManager
func _ready() -> void:
# ...
activities.register_steam(INSERT_STEAM_ID)
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.
-
activity: Discord.Activity
- The new activity for the user.
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.update_activity_callback(result: Discord.Result)
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([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.
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.clear_activity_callback(result: Discord.Result)
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(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.
-
user_id: int
- The user ID of the person who asked to join. -
reply: Discord.ActivityJoinRequestReply
- The response to send:No
,Yes
, orIgnore
.
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.send_request_reply_callback(result: Discord.Result)
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(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.
-
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.
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.send_invite_callback(result: Discord.Result)
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(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.
-
user_id: int
- The ID of the user who invited you.
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.accept_invite_callback(result: Discord.Result)
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.")
activity_join(join_secret: String)
Fires when a user accepts a game chat invite or receives confirmation from Asking to Join.
-
join_secret: String
- The secret to join the user's game.
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(spectate_secret: String)
Fires when a user accepts a spectate chat invite or clicks the Spectate button on a user's profile.
[Deprecated]
-
spectate_secret: String
- The secret to join the user's game as a spectator.
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(user: Discord.User)
Fires when a user asks to join the current user's game.
-
user: Discord.User
- The user asking to join.
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(type: Discord.ActivityActionType, user: Discord.User, activity: Discord.Activity)
Fires when the user receives a join or spectate invite.
-
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.
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(result: Discord.Result)
Alternative to the object & method args of update_activity
.
-
result: Discord.Result
- The result of the command.
clear_activity_callback(result: Discord.Result)
Alternative to the object & method args of clear_activity
.
-
result: Discord.Result
- The result of the command.
send_request_reply_callback(result: Discord.Result)
Alternative to the object & method args of send_request_reply
.
-
result: Discord.Result
- The result of the command.
send_invite_callback(result: Discord.Result)
Alternative to the object & method args of send_invite
.
-
result: Discord.Result
- The result of the command.
accept_invite_callback(result: Discord.Result)
Alternative to the object & method args of accept_invite
.
-
result: Discord.Result
- The result of the command.