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

This module (and its corresponding manager) can be used to retrieve basic information about a user on Discord, including the current one.

Contents

User Flag (Enum)

Discord.UserFlag

Description

Enum for different user flags.

Items

  • 2: PARTNER
  • 4: HYPESQUAD_EVENTS
  • 64: HYPESQUAD_HOUSE_1
  • 128: HYPESQUAD_HOUSE_2
  • 256: HYPESQUAD_HOUSE_3

Premium Type (Enum)

Discord.PremiumType

Description

Enum for different types of user premium subscriptions.

Items

  • 0: NONE
  • 1: TIER_1
  • 2: TIER_2

User

Discord.User

Extends Resource.

Description

Contains information about a User.

Properties

ID

id: int

The unique identifier of the user.

Default: 0

Username

username: String

The username of the user, limited to 255 characters.

Default: ""

Discriminator

discriminator: String

The user's unique tag, limited to 7 characters, but should only ever be 4 characters.

Default: ""

Avatar

avatar: String

The hash of the user's avatar, limited to 127 characters.

Default: ""

Bot

bot: bool

Whether the user is a bot user or not.

Default: false

User Manager

Discord.UserManager

Extends Object.

Description

Contains methods and events related to users.

Methods

Get Current User

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.

Optional Args

  • callback_target: Object - The callback target.

    callback_method: String - The callback method's name.

    get_current_user_callback(result: Discord.Result, user: Discord.User)

Example

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

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.

Arguments

  • user_id: int - The ID of the user to fetch.

Optional Args

  • callback_target: Object - The callback target.

    callback_method: String - The callback method's name.

    get_user_callback(result: Discord.Result, user: Discord.User)

Example

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

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.

Optional Args

  • 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)

Example

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

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.

Arguments

  • user_flag: Discord.UserFlag - The user flag to check for.

Optional Args

  • 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)

Example

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.")

Signals

Current User Update

current_user_update()

Called when the user has updated their information, or when the user is first fetched.

Example

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)

get_current_user_callback(result: Discord.Result, user: Discord.User)

Alternative to the object & method args of get_current_user.

Arguments

  • result: Discord.Result - The result of the command.

  • user: Discord.User - The current user data.

Get User (Callback)

get_user_callback(result: Discord.Result, user: Discord.User)

Alternative to the object & method args of get_user.

Arguments

  • result: Discord.Result - The result of the command.

  • user: Discord.User - The fetched user data.

Get Current User Premium Type (Callback)

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.

Arguments

  • result: Discord.Result - The result of the command.

  • premium_type: Discord.PremiumType - The premium type of the current user.

Current User Has Flag (Callback)

current_user_has_flag_callback(result: Discord.Result, has_flag: bool)

Alternative to the object & method args of current_user_has_flag.

Arguments

  • result: Discord.Result - The result of the command.

  • has_flag: bool - Whether the current user has the specified flag.

Clone this wiki locally