-
Notifications
You must be signed in to change notification settings - Fork 4
Users
This module (and its corresponding manager) can be used to retrieve basic information about a user on Discord, including the current one.
Discord.UserFlag
Enum for different user flags.
2: PARTNER
4: HYPESQUAD_EVENTS
64: HYPESQUAD_HOUSE_1
128: HYPESQUAD_HOUSE_2
256: HYPESQUAD_HOUSE_3
Discord.PremiumType
Enum for different types of user premium subscriptions.
0: NONE
1: TIER_1
2: TIER_2
Discord.User
Extends Resource
.
Contains information about a User.
id: int
The unique identifier of the user.
Default: 0
username: String
The username of the user, limited to 255 characters.
Default: ""
discriminator: String
The user's unique tag, limited to 7 characters, but should only ever be 4 characters.
Default: ""
avatar: String
The hash of the user's avatar, limited to 127 characters.
Default: ""
bot: bool
Whether the user is a bot user or not.
Default: false
Discord.UserManager
Extends Object
.
Contains methods and events related to users.
get_current_user([callback_target: Object, callback_method: String]) -> void
Gets the current user, and returns it via a callback.
Has a corresponding signal get_current_user_callback
that can be used instead of the optional target & method args.
Should only be called after the current_user_update
signal is released.
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.get_current_user_callback(result: Discord.Result, user: Discord.User)
var discord: Discord.Core
var users: Discord.UserManager
func _ready() -> void:
# ...
yield(users, "current_user_update")
users.get_current_user(self, "_get_current_user_callback")
func _get_current_user_callback(result: int, user: Discord.User) -> void:
if result != Discord.Result.OK:
print("Failed to get current user: ", result)
return
print("Got current user: ", user.username, "#", user.discriminator)
get_user(user_id: int, [callback_target: Object, callback_method: String]) -> void
Gets the user of a given ID, and returns it via a callback.
Has a corresponding signal get_user_callback
that can be used instead of the optional target & method args.
-
user_id: int
- The ID of the user to fetch.
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.get_user_callback(result: Discord.Result, user: Discord.User)
var discord: Discord.Core
var users: Discord.UserManager
func _ready() -> void:
# ...
users.get_user(425340416531890178, self, "_get_user_callback")
func _get_user_callback(result: int, user: Discord.User) -> void:
if result != Discord.Result.OK:
print("Failed to get user: ", result)
return
print("Got user: ", user.username, "#", user.discriminator)
get_current_user_premium_type([callback_target: Object, callback_method: String]) -> void
Gets the current user's premium type, and returns it via a callback.
Has a corresponding signal get_current_user_premium_type_callback
that can be used instead of the optional target & method args.
Should only be called after the current_user_update
signal is released.
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.get_current_user_premium_type_callback(result: Discord.Result, premium_type: Discord.PremiumType)
var discord: Discord.Core
var users: Discord.UserManager
func _ready() -> void:
# ...
yield(users, "current_user_update")
users.get_current_user_premium_type(
self,
"_get_current_user_premium_type_callback"
)
func _get_current_user_premium_type_callback(result: int, premium_type: int) -> void:
if result != Discord.Result.OK:
print(
"Failed to get current user's premium type: ",
result
)
return
print(
"Got current user's premium type: ",
premium_type
)
current_user_has_flag(user_flag: Discord.UserFlag, [callback_target: Object, callback_method: String]) -> void
Checks if the current user has the flag given.
Has a corresponding signal current_user_has_flag_callback
that can be used instead of the optional target & method args.
Should only be called after the current_user_update
signal is released.
-
user_flag: Discord.UserFlag
- The user flag to check for.
-
callback_target: Object
- The callback target.callback_method: String
- The callback method's name.current_user_has_flag_callback(result: Discord.Result, has_flag: bool)
var discord: Discord.Core
var users: Discord.UserManager
func _ready() -> void:
# ...
yield(users, "current_user_update")
users.current_user_has_flag(
Discord.UserFlag.HYPESQUAD_HOUSE_1
self, "_current_user_has_flag_callback"
)
func _current_user_has_flag_callback(result: int, has_flag: bool) -> void:
if result != Discord.Result.OK:
print(
"Failed to see if the current user is part of Hype Squad House 1: ",
result
)
if has_flag:
print("Current user is in Hypesquad House 1.")
else:
print("Current user isn't in Hypesquad House 1.")
current_user_update()
Called when the user has updated their information, or when the user is first fetched.
var discord: Discord.Core
var users: Discord.UserManager
func _ready() -> void:
# ...
users.connect(
"current_user_update",
self, "_on_current_user_update"
)
func _on_current_user_update() -> void:
print("The current user was updated.")
get_current_user_callback(result: Discord.Result, user: Discord.User)
Alternative to the object & method args of get_current_user
.
-
result: Discord.Result
- The result of the command. -
user: Discord.User
- The current user data.
get_user_callback(result: Discord.Result, user: Discord.User)
Alternative to the object & method args of get_user
.
-
result: Discord.Result
- The result of the command. -
user: Discord.User
- The fetched user data.
get_current_user_premium_type_callback(result: Discord.Result, premium_type: Discord.PremiumType)
Alternative to the object & method args of get_current_user_premium_type
.
-
result: Discord.Result
- The result of the command. -
premium_type: Discord.PremiumType
- The premium type of the current user.
current_user_has_flag_callback(result: Discord.Result, has_flag: bool)
Alternative to the object & method args of current_user_has_flag
.
-
result: Discord.Result
- The result of the command. -
has_flag: bool
- Whether the current user has the specified flag.