Comments, Friend Requests and Messages

gd.py implements reading, sending and interacting with comments, friend requests and messages:

client = gd.Client()

# we can only read comments if we are not logged in.
await client.login("username", "password")

nekit = await client.search_user("nekitdev")
# <User name='nekitdev' id=17876467 account_id=5509312>

async for comment in nekit.get_profile_comments():
    print(comment.body)

# find some featured level by user
level = await nekit.search_levels().find(lambda level: level.is_featured())

# if found, print comments
if level is not None:
    async for comment in level.get_comments():
        print(comment)

# print some messages
async for message in client.get_messages():
    print(message.author.name, message.subject)

# send a friend request
await nekit.send_friend_request("Sent from gd.py")

# post a comment
await client.post_comment("This comment is posted using gd.py")

Comment

class gd.Comment(*, client: Optional[Client] = None, **options)[source]

Class that represents a Profile/Level comment in Geometry Dash. This class is derived from AbstractEntity.

x == y

Check if two objects are equal. Compared by hash and type.

x != y

Check if two objects are not equal.

str(x)

Return content of the comment.

repr(x)

Return representation of the comment, useful for debugging.

hash(x)

Returns hash(self.hash_str).

classmethod from_model(model: gd.model.CommentModel, *, client: Optional[Client] = None, user: Optional[gd.user.User] = None)Comment[source]

Initialize Comment from CommentModel.

Parameters
  • model (CommentModel) – Comment model to use.

  • client (Optional[Client]) – Client to attach.

  • user (Optional[User]) – Author of the comment to use, if not in model.

Returns

New comment instance.

Return type

Comment

property content

Content of the comment.

Type

str

property body

Content of the comment.

Type

str

property rating

Rating of the comment.

Type

int

property created_at

Optional[datetime]: Timestamp representing when the comment was created.

property author

An author of the comment.

Type

User

property type

Whether comment is on profile or on a level.

Type

CommentType

property level_id

Level ID of a level the comment is on. 0 if profile comment.

Type

int

property level_percent

Level highscore linked to a comment. -1 if profile comment.

Type

int

property color

Color of the comment. Often equals gd.Color(0xffffff).

Type

Color

is_spam()bool[source]

bool: Indicates whether a comment is marked as spam. False if profile comment.

is_disliked()bool[source]

bool: Indicates whether a comment is disliked or not.

async like()None[source]

Likes a comment.

Raises
async dislike()None[source]

Dislikes a comment.

Raises
async delete()None[source]

Deletes a comment from Geometry Dash servers.

Raises
attach_client(client: Optional[Client] = None)AbstractEntityT

Attach client to self.

Parameters

client (Optional[gd.Client]) – Client to attach. If None or not given, will be detached.

Returns

This abstract entity.

Return type

AbstractEntity

property client

Client attached to this object. This checks if client is not present, and raises ClientException in that case.

Type

Client

property client_unchecked

Client attached to this object.

Type

Optional[Client]

detach_client()AbstractEntityT

Detach client from self.

Same as calling:

self.attach_client(None)
Returns

This abstract entity.

Return type

AbstractEntity

classmethod from_dict(*data: Dict[str, Any], client: Optional[Client] = None, **kwargs)AbstractEntityT

Create new entity from dictionaries in data, with client and kwargs.

classmethod from_dicts(*data: Dict[str, Any], client: Optional[Client] = None, **kwargs)AbstractEntityT

Create new entity from dictionaries in data, with client and kwargs.

classmethod from_models(*models: gd.model_backend.Model, **kwargs)AbstractEntityT

Create new entity from given models by calling from_model with kwargs.

property hash_str

String used for hashing, with format <Class(ID->id)>.

Type

str

property id

ID of the Entity.

Type

int

to_dict()Dict[str, Any]

Convert the entity to a dictionary.

update_inner(**options: Any)AbstractEntityT

Update self.options with options.

Friend Request

class gd.FriendRequest(*, client: Optional[Client] = None, **options)[source]

Class that represents a friend request. This class is derived from AbstractEntity.

x == y

Check if two objects are equal. Compared by hash and type.

x != y

Check if two objects are not equal.

str(x)

Return content of the friend request.

repr(x)

Return representation of the friend request, useful for debugging.

hash(x)

Returns hash(self.hash_str).

classmethod from_model(model: gd.model.FriendRequestModel, *, client: Optional[Client] = None, other_user: Optional[gd.user.User] = None, type: gd.enums.FriendRequestType = <FriendRequestType.INCOMING: 0>)FriendRequest[source]

Create new entity from given model, args and kwargs.

property author

Author of the friend request.

Type

User

property recipient

Recipient of the friend request.

Type

User

property type

Whether request is incoming or sent.

Type

FriendRequestType

property content

Friend request message.

Type

str

property body

Friend request message.

Type

str

property created_at

Optional[datetime]: Timestamp representing when friend request was created.

is_read()bool[source]

bool: Indicates whether request was read.

async read()None[source]

Read a friend request. Sets is_read to True on success.

Raises
async delete()None[source]

Delete a friend request.

Raises
async accept()None[source]

Accept a friend request.

Raises
attach_client(client: Optional[Client] = None)AbstractEntityT

Attach client to self.

Parameters

client (Optional[gd.Client]) – Client to attach. If None or not given, will be detached.

Returns

This abstract entity.

Return type

AbstractEntity

property client

Client attached to this object. This checks if client is not present, and raises ClientException in that case.

Type

Client

property client_unchecked

Client attached to this object.

Type

Optional[Client]

detach_client()AbstractEntityT

Detach client from self.

Same as calling:

self.attach_client(None)
Returns

This abstract entity.

Return type

AbstractEntity

classmethod from_dict(*data: Dict[str, Any], client: Optional[Client] = None, **kwargs)AbstractEntityT

Create new entity from dictionaries in data, with client and kwargs.

classmethod from_dicts(*data: Dict[str, Any], client: Optional[Client] = None, **kwargs)AbstractEntityT

Create new entity from dictionaries in data, with client and kwargs.

classmethod from_models(*models: gd.model_backend.Model, **kwargs)AbstractEntityT

Create new entity from given models by calling from_model with kwargs.

property hash_str

String used for hashing, with format <Class(ID->id)>.

Type

str

property id

ID of the Entity.

Type

int

to_dict()Dict[str, Any]

Convert the entity to a dictionary.

update_inner(**options: Any)AbstractEntityT

Update self.options with options.

Message

class gd.Message(*, client: Optional[Client] = None, **options)[source]

Class that represents private messages in Geometry Dash. This class is derived from AbstractEntity.

x == y

Check if two objects are equal. Compared by hash and type.

x != y

Check if two objects are not equal.

str(x)

Return content of the message. Empty if the message was not read yet.

repr(x)

Return representation of the message, useful for debugging.

hash(x)

Returns hash(self.hash_str).

classmethod from_model(model: gd.model.MessageModel, *, client: Optional[Client] = None, other_user: Optional[gd.user.User] = None, type: gd.enums.MessageType = <MessageType.INCOMING: 0>)Message[source]

Create new entity from given model, args and kwargs.

property author

Author of the message.

Type

User

property recipient

Recipient of the message.

Type

User

property subject

A subject of the message, as string.

Type

str

property created_at

Optional[datetime]: Timestamp representing when the message was created.

property type

Whether a message is sent or incoming.

Type

MessageType

get_content()Optional[str][source]

Optional[str]: Content of the message. Requires read().

set_content(content: str)None[source]

Set self.content to content.

property content

Content of the message. Requires read().

Type

Optional[str]

property body

Content of the message. Requires read().

Type

Optional[str]

is_read()bool[source]

bool: Indicates whether message is read or not.

async read()str[source]

Read a message. Set the body of the message to the content.

Raises
Returns

The content of the message.

Return type

str

async reply(content: str, schema: Optional[str] = None)Optional[gd.message.Message][source]

Reply to the message. Format the subject according to schema.

Schema format can only contain {message.attribute} elements.

Content also allows schema format.

Example:

await message.reply(
    content="Replying to message by {message.author.name}."
    schema="Re: {message.subject} ({message.rating})"
)
Raises
Returns

Sent message, or None if load_after_post is False.

Return type

Optional[Message]

async delete()None[source]

Delete a message.

Raises
attach_client(client: Optional[Client] = None)AbstractEntityT

Attach client to self.

Parameters

client (Optional[gd.Client]) – Client to attach. If None or not given, will be detached.

Returns

This abstract entity.

Return type

AbstractEntity

property client

Client attached to this object. This checks if client is not present, and raises ClientException in that case.

Type

Client

property client_unchecked

Client attached to this object.

Type

Optional[Client]

detach_client()AbstractEntityT

Detach client from self.

Same as calling:

self.attach_client(None)
Returns

This abstract entity.

Return type

AbstractEntity

classmethod from_dict(*data: Dict[str, Any], client: Optional[Client] = None, **kwargs)AbstractEntityT

Create new entity from dictionaries in data, with client and kwargs.

classmethod from_dicts(*data: Dict[str, Any], client: Optional[Client] = None, **kwargs)AbstractEntityT

Create new entity from dictionaries in data, with client and kwargs.

classmethod from_models(*models: gd.model_backend.Model, **kwargs)AbstractEntityT

Create new entity from given models by calling from_model with kwargs.

property hash_str

String used for hashing, with format <Class(ID->id)>.

Type

str

property id

ID of the Entity.

Type

int

to_dict()Dict[str, Any]

Convert the entity to a dictionary.

update_inner(**options: Any)AbstractEntityT

Update self.options with options.