API-Reference#
The API-Reference of the wrapper. Contains all methods and classes usable.
Meta#
Misc information about the wrapper.
Version#
- rin.__version__#
- The current version of the wrapper.
Caching#
Things regarding caching and caches in the wrapper.
Cache#
- class rin.Cache#
A class which represents an in-memory cache.
Note
All cache-able classes have this class under the attribute Class.cache
user: rin.User = rin.User.cache.get(123) rin.User.cache.set(123, User)
- Parameters
max (None |
int
) – The max amount of items before poping the last inserted object.
- iterator()#
An iterator for the cache’s values.
- Returns
An iterator of the values.
- Return type
typing.Iterator[T]
- set(key, value)#
Sets a key to the given value.
- get(key)#
Retrieves a value from the given key.
Cacheable#
API Interface#
Things in regard to handling and helping use of the API.
GatewayClient#
- class rin.GatewayClient#
A client which makes a connection to the gateway.
This client is used to receive events from the gateway. This client also can utilize RESTful requests.
- Parameters
token (
str
) – The token to use for authorization.no_chunk (
bool
) – If chunking at startup should be disabled.loop (None |
asyncio.AbstractEventLoop
) – The loop to use for async operations.intents (
int
) – The intents to identify with when connecting to the gateway.
- loop#
The loop being used for async operations.
- rest#
The RESTful request handler.
- Type
- gateway#
The gateway handler for the client.
- Type
Gateway
- dispatcher#
The dispatch manager for the client.
- Type
Dispatcher
- @on(self, event, check=<function GatewayClient.<lambda>>)#
Registers a callback to an event.
- Parameters
event (
Event
) – The event to register to.check (Callable[…,
bool
]) – The check the event has to pass in order to be dispatched.
- Return type
Callable[…,
Listener
]
- @once(self, event, check=<function GatewayClient.<lambda>>)#
Registers a onetime callback to an event. :param event: The event to register to. :type event:
Event
:param check: The check the event has to pass in order to be dispatched. :type check: Callable[…,bool
]- Return type
Callable[…,
Listener
]
- async start()#
Starts the connection.
This method starts the connection to the gateway.
- Return type
None
- async close()#
Closes the client.
This method closes the gateway connection as well as the
aiohttp.ClientSession
used by RESTClient.- Parameters
reason (
str
) – The reason to close the client with.- Return type
None
- sender(snowflake)#
Creates a
MessageBuilder
from the client.
- unserialize(data, *, cls)#
Un-serializes a serialized object. Used for persistent objects.
Note
Objects could be inaccurate or outdated. It’s suggested that you verify the object to be correct.
- dispatch(event, *payload)#
Dispatches an event.
Examples
client.dispatch(rin.Events.MESSAGE_CREATE, rin.Message(...)) # Here `rin.Message(...)` is the payload that gets dispatched to the event's callback.
- Parameters
event (
Event
) – The event to dispatch.payload (Any) – The payload to dispatch the event with.
- Returns
A list of tasks created by the dispatch call.
- Return type
list[
asyncio.Task
]
- collect(event, *, amount, timeout=None, check=<function GatewayClient.<lambda>>)#
Registers a collector to an event.
Arguments of the callback will be passed as lists when the event has been collected X amount of times.
RESTClient#
- class rin.RESTClient#
The class used to make RESTful API requests.
This class implements requesting which works in tandem with the concurrent request ratelimit system. Allows for safe requesting and bucket depletion handling.
Note
The session attribute is only set after at least 1 request.
- Parameters
token (
str
) – The token used for authorization.client (
GatewayClient
) – The client being used.
- session#
The session assiocated with the RESTClient.
- client#
The client being used.
- Type
- semaphores#
The semaphores used for each bucket. This is used to ensure safety and allowing concurrent requests.
- Type
dict[str,
asyncio.Semaphore
]
- async connect(url)#
Makes a connection to the gateway.
- Parameters
url (
str
) – The url of the gateway.- Returns
The gateway after connection is made.
- Return type
Gateway
- async request(method, route, **kwargs)#
Makes a request to the Route.
A safe request method of the client. Ensures bucket depletion is safe along with global ratelimits.
- Parameters
- Raises
.HTTPException – Something went wrong with the request.
- Returns
The return data from the request.
- Return type
Any
Route#
- class rin.Route#
- BASE = 'https://discord.com/api/v{0}/'#
Route used for RESTful requests.
This class is used in the wrapper where requests are made. The wrapper does not have a centralized part that has all predefined RESTful calls. The wrapper will instead utilize Routes in class depedent methods to make their respective requests.
- Parameters
endpoint (
str
) – The endpoint of the Route.version (
str
) – The version of the RESTful API to use.channel_id (None |
int
) – The channel ID being used. This is used for bucket specificity.guild_id (None |
int
) – The guild ID being used. This is used for bucket specificity.webhook_id (None |
int
) – The webhook ID being used. This is used for bucket specificity.webhook_token (None |
str
) – The webhook token being used. This is used for bucket specificity.
- event#
The event used for the bucket once depleted. Used in tandem with the concurrent request ratelimit system. Allowing safe concurrent requests.
- Type
Errors#
Errors used in the wrapper.
HTTPException#
BadRequest#
- exception rin.BadRequest#
Bases:
rin.rest.errors.HTTPException
Represents a 400 HTTP error.
Forbidden#
- exception rin.Forbidden#
Bases:
rin.rest.errors.HTTPException
Represents a 403 HTTP error.
NotFound#
- exception rin.NotFound#
Bases:
rin.rest.errors.HTTPException
Represents a 404 HTTP error.
Builders#
Model builders.
IntentsBuilder#
- class rin.IntentsBuilder#
A helper class for Intents. Creates an intent value from passed in keyword-arguments.
Note
All valid intents for
Intents.create()
are shown below but with lowercased names. Privileged intents are prefixed with a !.NAME
VALUE
USE
GUILDS
1 << 0
GUILD_CREATE
GUILD_UPDATE
GUILD_DELETE
GUILD_ROLE_CREATE
GUILD_ROLE_UPDATE
GUILD_ROLE_DELETE
CHANNEL_CREATE
CHANNEL_UPDATE
CHANNEL_DELETE
CHANNEL_PINS_UPDATE
THREAD_CREATE
THREAD_UPDATE
THREAD_DELETE
THREAD_LIST_SYNC
THREAD_MEMBER_UPDATE
THREAD_MEMBERS_UPDATE *
STAGE_INSTANCE_CREATE
STAGE_INSTANCE_UPDATE
STAGE_INSTANCE_DELETE
!GUILD_MEMBERS
1 << 1
GUILD_MEMBER_ADD
GUILD_MEMBER_UPDATE
GUILD_MEMBER_REMOVE
THREAD_MEMBERS_UPDATE *
GUILD_BANS
1 << 2
GUILD_BAN_ADD
GUILD_BAN_REMOVE
GUILD_EMOJIS_AND_STICKERS
1 << 3
GUILD_EMOJIS_UPDATE
GUILD_STICKERS_UPDATE
GUILD_INTEGRATIONS
1 << 4
GUILD_INTEGRATIONS_UPDATE
INTEGRATION_CREATE
INTEGRATION_UPDATE
INTEGRATION_DELETE
GUILD_WEBHOOKS
1 << 5
WEBHOOKS_UPDATE
GUILD_INVITES
1 << 6
INVITE_CREATE
INVITE_DELETE
GUILD_VOICE_STATES
1 << 7
VOICE_STATE_UPDATE
!GUILD_PRESENCES
1 << 8
PRESENCE_UPDATE
GUILD_MESSAGES
1 << 9
MESSAGE_CREATE
MESSAGE_UPDATE
MESSAGE_DELETE
MESSAGE_DELETE_BULK
GUILD_MESSAGE_REACTIONS
1 << 10
MESSAGE_REACTION_ADD
MESSAGE_REACTION_REMOVE
MESSAGE_REACTION_REMOVE_ALL
MESSAGE_REACTION_REMOVE_EMOJI
GUILD_MESSAGE_TYPING
1 << 11
TYPING_START
DIRECT_MESSAGES
1 << 12
MESSAGE_CREATE
MESSAGE_UPDATE
MESSAGE_DELETE
CHANNEL_PINS_UPDATE
DIRECT_MESSAGE_REACTIONS
1 << 13
MESSAGE_REACTION_ADD
MESSAGE_REACTION_REMOVE
MESSAGE_REACTION_REMOVE_ALL
MESSAGE_REACTION_REMOVE_EMOJI
DIRECT_MESSAGE_TYPING
1 << 14
TYPING_START
GUILD_SCHEDULED_EVENTS
1 << 16
GUILD_SCHEDULED_EVENT_CREATE
GUILD_SCHEDULED_EVENT_UPDATE
GUILD_SCHEDULED_EVENT_DELETE
GUILD_SCHEDULED_EVENT_USER_ADD
GUILD_SCHEDULED_EVENT_USER_REMOVE
- classmethod create(**kwargs)#
Creates an intents instance with a value specific to the passed in keyword-arguments.
Examples
intents = Intents.create(guild_members=True)
- Parameters
kwargs (
bool
) – Keyword-arguments specific to the Intent with True/False value.- Returns
A created intents instance with a value corresponding to the keyword-arguments passed.
- Return type
Intents
- classmethod default(**kwargs)#
Creates an intents instance without privileged intents.
- Parameters
kwargs (class:bool) – Extra intents to create along side the default ones.
- Returns
A created intents instance with the corresponding value.
- Return type
Intents
- classmethod privileged(**kwargs)#
Creates an intents instance with only privileged intents.
- Parameters
kwargs (class:bool) – Extra intents to create along side the privileged ones.
- Returns
A created intents instance with the corresponding value.
- Return type
Intents
- classmethod none()#
Creates an intents instance without any intents.
- Returns
A created intents instance with no value.
- Return type
Intents
EmbedBuilder#
- class rin.EmbedBuilder#
- classmethod from_dict(data)#
Creates an Embed object from a dict.
- Parameters
data (
dict
) – The data to create the embed from- Returns
A created embed from the dict.
- Return type
- to_dict()#
Creates a dict representing the embed.
- Returns
The dict representing the embed.
- Return type
The embed’s footer.
Sets the embed’s footer.
- set_image(url, height=None, width=None)#
Sets the embed’s image.
- set_thumbnail(url, height=None, width=None)#
Sets the embed’s thumbnail.
- set_video(url, height=None, width=None)#
Sets the embed’s video.
- set_provider(name=None, url=None)#
Sets the embed’s provider.
- set_author(name, url=None, icon_url=None)#
Sets the embed’s author.
MessageBuilder#
- class rin.MessageBuilder#
A helper class used to add messaging functionality.
This class is intended to be used both internally and in frontend. It is encouraged to construct this class when sending a message without an object. This allows for users to not have a full object to send messages.
- client#
The client being used to send a message.
- Type
- set_snowflake(snowflake)#
A helper method ued to set the snowflake of the instance. Useful for classes such as a DM Channel.
- Parameters
snowflake (
Snowflake
) – The snowflake to set.- Return type
None
- async send(content=None, tts=False, embeds=[], files=[], rows=[], reply=None, mentions=AllowedMentions(everyone=True, roles=True, users=True, replied_user=True))#
Sends a message into the channel corresponding to the passed in
Snowflake
.- Parameters
content (None |
str
) – The content to give the message.tts (
bool
) – If the message should be sent with text-to-speech. Defaults to False.embeds (
list
) – A list ofEmbedBuilder
instances to send with the message.files (
list
) – A list ofFile
instances to send with the message.reply (None |
Message
) – The message to reply to.mentions (
AllowedMentions
) – The allowed mentions of the message.rows (list[ActionRow]) –
- Returns
An instance of the newly sent message.
- Return type
ANSIBuilder#
- class rin.ANSIBuilder#
A helper class to build ANSI codeblocks.
- lines#
A list of
str
which have been created. This will be all joined together when finalizing the construction.- Type
- new(text, *, mode=Mode.BOLD, fore=Color.DEFAULT, back=Color.DEFAULT, reset_after=True, new_line=True)#
Creates a new string using the mode passed in.
- Parameters
text (
str
) – The message to color/style.mode (
Mode
) – The mode to use, E.g BOLD, DIM etc.fore (
Color
) – The foreground color to use.back (
Color
) – The background color to use.reset_after (
bool
) – If a reset code should be added after adding the new line.new_line (
bool
) – If a new line should be added after adding this one.
- Return type
None
- colorful(text, *, mode=Mode.BOLD)#
Turns a string into a colorful one.
- clear()#
Clears the current lines of the builder.
- Return type
None
- class rin.Mode#
Mode enum. Holds all supported ANSI modes.
- class rin.Color#
Color enum. Holds all supported ANSI colors.
Each enum contains a tuple of two elements, the first being the forground color code, and the second being the background color code.
Assets#
Classes/Models used for assets.
File#
- class rin.File#
A helper class for files.
- Parameters
fp (
str
|os.PathLike
|bytes
) – The file path of the class, or source.name (None |
str
) – The name of the file.
- fp#
The file path of the class, or source.
- Type
str
|os.PathLike
|bytes
- read(size)#
Reads the bytes of the file.
- close()#
Closes the file.
- Return type
None
Models#
Models in the wrapper.
BaseModel#
- class rin.BaseModel#
- static field(key=None, type=<class 'str'>, **kwargs)#
Sets a field for the class.
Acts as almost a placeholder value. Actual value is set on construction.
- static property(key, type=<class 'str'>, **kwargs)#
Sets a property of the class. Used for adding a constructor.
- construct()#
This method actually handles construction of attributes.
This method will iterate through all the fields specified on this class. It will then check the type of the field by looking through the metadata.
- Return type
None
Snowflake#
- class rin.Snowflake#
Bases:
int
Represents a snowflake.
- static __new__(cls, *args, **kwargs)#
- Parameters
- Return type
- property created_at: datetime.datetime#
The time at which the snowflake was created.
AllowedMentions#
- class rin.AllowedMentions#
Represents an allowed mentions object.
This is used to determine the allowed mentions of any messages being sent from the client’s user.
- Parameters
everyone (
bool
) – If mentioning everyone is allowed. By default True.roles (
bool
|list
) – Either a list of role IDs, or a boolean value. Determines the allowed roles to be mentioned.users (
bool
|list
) – Either a list of user IDs, or a boolean value. Dtermines the allowed users to be mentioned.replied_user (
bool
) – If mentioning the replied user to the message is allowed.
- classmethod none()#
Creates a
AllowedMentions
instance that has no allowed mentions set.- Returns
The created instance.
- Return type
Message#
- class rin.Message#
Bases:
rin.models.base.BaseModel
,rin.models.cacheable.Cacheable
Represents a Message.
- guild_id#
The snowflake of the guild the message was sent in. None if the message was sent inside of a direct-message channel.
- Type
None |
Snowflake
- interaction#
The interaction of the message. Only given when the message is an interaction response.
- Type
None |
dict
- type#
The message’s type.
- Type
MessageType
- embeds#
A list of embeds sent with the message.
- Type
list[
EmbedBuilder
]
- timestamp#
The timestamp for when the message was created.
- Type
- editted_at#
The time when the message was editted. None if the message hasn’t been editted.
- Type
- reference()#
Creates a message reference from the instance.
- Returns
The created dict representing the message’s reference.
- Return type
- async reply(content=None, tts=False, embeds=[], files=[], rows=[], mentions=AllowedMentions(everyone=True, roles=True, users=True, replied_user=True))#
Sends a message repyling to this message into the channel corresponding to the passed in
Snowflake
.- Parameters
content (None |
str
) – The content to give the message.tts (
bool
) – If the message should be sent with text-to-speech. Defaults to False.embeds (
list
) – A list ofEmbedBuilder
instances to send with the message.files (
list
) – A list ofFile
instances to send with the message.mentions (
AllowedMentions
) – The allowed mentions of the message.rows (list[ActionRow]) –
- Returns
An instance of the newly sent message.
- Return type
- async delete()#
Deletes the message.
- Raises
.HTTPException – Something went wrong.
- Return type
None
- async react(reaction)#
Adds a reaction to the message.
- Parameters
reaction (
str
) – The reaction to react with.- Raises
.HTTPException – Something went wrong.
- Return type
None
- async delete_reaction(reaction, user=None)#
Deletes a reaction from the message.
- async pin()#
Pins the message.
- Raises
.HTTPException – Something went wrong while making the request.
- Return type
None
- async unpin()#
Unpins the message.
- Raises
.HTTPException – Something went wrong while making the request.
- Return type
None
User#
- class rin.User#
Bases:
rin.models.base.BaseModel
,rin.models.cacheable.Cacheable
Represents a discord user.
- bot :class:`bool`
If the user is a bot user.
- email#
The user’s email which is connected to the account. Given with the email scope.
- Type
None |
str
The premium type of the user. Given with the identify scope.
- Type
- async edit(username=None, avatar=None)#
Edits the current authorized user.
- Parameters
- Raises
HTTPException – Something went wrong.
- Returns
The user after editting is finished.
- Return type