Wumpus.py API Reference¶
Client¶
- class wumpus.Client(*, intents: Optional[wumpus.models.intents.Intents] = None, http_version: Literal[3, 4, 5, 6, 7, 8, 9] = 9, gateway_version: Literal[4, 5, 6, 7, 8, 9] = 9, loop: Optional[asyncio.events.AbstractEventLoop] = None)¶
Represents a client connection to Discord.
- async fetch_guild_preview(id: int) wumpus.models.guild.GuildPreview¶
This function is a coroutine.
Fetches a
GuildPreviewby it’s ID.Note
If the client is not in the guild, then the guild must be lurkable.
- Parameters
id (Snowflake) – The snowflake ID of the guild to fetch.
- Returns
- Return type
- async login(token: Optional[str] = None, /) None¶
This function is a coroutine.
Establishes an HTTP session to Discord.
- property loop: asyncio.events.AbstractEventLoop¶
The event loop this client is using.
- property user: wumpus.models.user.ClientUser¶
ClientUserThe Discord user this client represents.
- class wumpus.Emitter¶
Objects¶
- class wumpus.Object(id: Optional[int] = None, /)¶
Represents a Discord object.
- property created_at: wumpus.models.objects.Timestamp¶
The creation timestamp of this object.
- Type
- property id: int¶
The snowflake ID of this object.
- Type
Snowflake
- class wumpus.Timestamp(year: int, month: Optional[int] = None, day: Optional[int] = None, hour: int = 0, minute: int = 0, second: int = 0, microsecond: int = 0, tzinfo: datetime.timezone = timezone.utc, *, fold: int = '0')¶
Represents a timestamp of something related to Discord. This inherits from
datetime.datetime.There are some major differences from datetime and this class:
This class defaults to timezone-aware datetimes for consistency.
- When used in format strings, a “formatted timestamp” in the form of <t:unix:?format> is returned.
This can be convenient, for example: f”This user was created {user.created_at:R}.”
- astimezone()¶
tz -> convert to local time in new timezone tz
- combine()¶
date, time -> datetime with same date and time fields
- ctime()¶
Return ctime() style string.
- date()¶
Return date object with same year, month and day.
- dst()¶
Return self.tzinfo.dst(self).
- classmethod from_datetime(dt: datetime.datetime, /) wumpus.models.objects.DT¶
Casts a
datetime.datetimeinto aTimestamp.- Parameters
dt (
datetime.datetime) – The datetime to use.- Returns
- Return type
- fromisocalendar()¶
int, int, int -> Construct a date from the ISO year, week number and weekday.
This is the inverse of the date.isocalendar() function
- fromisoformat()¶
string -> datetime from datetime.isoformat() output
- fromordinal()¶
int -> date corresponding to a proleptic Gregorian ordinal.
- fromtimestamp()¶
timestamp[, tz] -> tz’s local time from POSIX timestamp.
- isocalendar()¶
Return a 3-tuple containing ISO year, week number, and weekday.
- isoformat()¶
[sep] -> string in ISO 8601 format, YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM]. sep is used to separate the year from the time, and defaults to ‘T’. timespec specifies what components of the time to include (allowed values are ‘auto’, ‘hours’, ‘minutes’, ‘seconds’, ‘milliseconds’, and ‘microseconds’).
- isoweekday()¶
Return the day of the week represented by the date. Monday == 1 … Sunday == 7
- classmethod now() wumpus.models.objects.DT¶
Return the current timestamp, timezone aware.
- Returns
- Return type
- replace()¶
Return datetime with new specified fields.
- strftime()¶
format -> strftime() style string.
- strptime()¶
string, format -> new datetime parsed from a string (like time.strptime()).
- time()¶
Return time object with same time but with tzinfo=None.
- timestamp()¶
Return POSIX timestamp as float.
- timetuple()¶
Return time tuple, compatible with time.localtime().
- timetz()¶
Return time object with same time and tzinfo.
- to_datetime() datetime.datetime¶
Casts this into a
datetime.datetime.- Returns
- Return type
- to_snowflake(*, worker_id: int = 1, process_id: int = 0, increment: Optional[int] = None) int¶
Generates a snowflake ID from this timestamp.
All parameters are keyword-only and optional.
- today()¶
Current date or datetime: same as self.__class__.fromtimestamp(time.time()).
- toordinal()¶
Return proleptic Gregorian ordinal. January 1 of year 1 is day 1.
- tzname()¶
Return self.tzinfo.tzname(self).
- classmethod utcfromtimestamp(timestamp: float, /) wumpus.models.objects.DT¶
Return the timestamp from the given Unix timestamp.
- classmethod utcnow() wumpus.models.objects.DT¶
An alias for
Timestamp.now().- Returns
- Return type
- utcoffset()¶
Return self.tzinfo.utcoffset(self).
- utctimetuple()¶
Return UTC time tuple, compatible with time.localtime().
- weekday()¶
Return the day of the week represented by the date. Monday == 0 … Sunday == 6
Snowflake
A type alias for int.
This is used when a type should be a “snowflake ID”.
User¶
- class wumpus.User(connection: wumpus.core.connection.Connection, /, data: Optional[wumpus.typings.payloads.PartialUserPayload] = None)¶
Represents a Discord user.
- async create_dm() ...¶
This function is a coroutine.
Opens a DM with this user. This is implicitly called, this should not be used frequently.
- property created_at: wumpus.models.objects.Timestamp¶
The creation timestamp of this object.
- Type
- property id: int¶
The snowflake ID of this object.
- Type
Snowflake
- property tag: str¶
The user’s name and discriminator in the conventional name#discrim format.
- Type
- to_dict() wumpus.typings.payloads.PartialUserPayload¶
Converts this user into a raw dictionary that can be sent to Discord.
- Returns
- Return type
JSON
- class wumpus.ClientUser(connection: wumpus.core.connection.Connection, /, data: Optional[wumpus.typings.payloads.PartialUserPayload] = None)¶
Represents the user that represents the client.
- property created_at: wumpus.models.objects.Timestamp¶
The creation timestamp of this object.
- Type
- async edit(*, name: Optional[str] = None, avatar: Union[str, bytes] = Ellipsis) None¶
This function is a coroutine.
Changes the name and/or avatar of this user. All parameters are keyword only, and they are all optional.
- property id: int¶
The snowflake ID of this object.
- Type
Snowflake
- property mfa_enabled: bool¶
Whether or not 2 factor authentication is enabled on this account.
- Type
- property tag: str¶
The user’s name and discriminator in the conventional name#discrim format.
- Type
- to_dict() wumpus.typings.payloads.UserPayload¶
Converts this user into a raw dictionary that can be sent to Discord.
- Returns
- Return type
JSON
Guild¶
- class wumpus.Guild(connection: wumpus.core.connection.Connection, /, data: wumpus.typings.payloads.GuildPayload)¶
- property created_at: Optional[wumpus.models.objects.Timestamp]¶
The creation timestamp of this object.
- Type
- property id: int¶
The snowflake ID of this object.
- Type
Snowflake
- class wumpus.GuildPreview(connection: wumpus.core.connection.Connection, /, data: wumpus.typings.payloads.GuildPreviewPayload)¶
Member¶
- class wumpus.Member(connection: Connection, data: JSON, *, guild: Guild, user: PartialUserPayload = None)¶
Represents a guild member. This inherits from
User.- async add_role(role: Union[Role, Object], /, *, reason: str = None) None¶
This function is a coroutine.
Adds a role to this member.
- async add_roles(*roles: Union[Role, Object], reason: str = None) None¶
This function is a coroutine.
Adds multiple roles to this member at once.
- async ban(*, reason: Optional[str] = None, delete_message_days: Literal[0, 1, 2, 3, 4, 5, 6, 7] = 1) None¶
This function is a coroutine.
Bans this member from it’s guild. This requires the ban_members permission.
This is equivalent to
Guild.ban().
- async create_dm() ...¶
This function is a coroutine.
Opens a DM with this user. This is implicitly called, this should not be used frequently.
- property created_at: wumpus.models.objects.Timestamp¶
The creation timestamp of this object.
- Type
- async edit(*, nick: str = None, roles: Iterable[Union[Role, Object]] = None, mute: bool = None, deaf: bool = None, reason: str = None) None¶
This function is a coroutine.
Edits attributes of this member. All parameters are keyword-only and optional.
- property id: int¶
The snowflake ID of this object.
- Type
Snowflake
- property joined_at: wumpus.models.objects.Timestamp¶
The timestamp for when this member joined it’s guild.
- Type
- async kick(reason: str, /) None¶
This function is a coroutine.
Removes this member from it’s guild. This requires the kick_members permission.
This is equivalent to
Guild.kick().- Parameters
reason (str) – The audit log reason to use.
- property nick: str¶
The member’s nickname. None if the member does not have one.
See also
- Type
- property permissions: wumpus.models.permissions.Permissions¶
The permissions for this member at the guild level.
Note
This does not account for channel overwrites. See
Member.permissions_in()for that.- Type
The timestamp for when this member started boosting this guild.
This will be None is the member is not boosting at all.
- Type
- async remove_role(role: Union[Role, Object], /, *, reason: str = None) None¶
This function is a coroutine.
Removes a role from this member.
- async remove_roles(*roles: Union[Role, Object], reason: str = None) None¶
This function is a coroutine.
Removes multiple roles from this member at once.
- property tag: str¶
The user’s name and discriminator in the conventional name#discrim format.
- Type
- to_dict() wumpus.typings.payloads.PartialUserPayload¶
Converts this user into a raw dictionary that can be sent to Discord.
- Returns
- Return type
JSON
Role¶
- class wumpus.Role(connection: Connection, guild: Guild, data: JSON, /)¶
Represents a Discord role inside of a guild.
- permissions¶
The permissions this role has.
- Type
- color¶
The color of this role.
- Type
Color
- property created_at: wumpus.models.objects.Timestamp¶
The creation timestamp of this object.
- Type
- async delete(*, reason: Optional[str] = None) None¶
This function is a coroutine.
Deletes this role.
- Parameters
reason (str) – The audit log reason to use.
- async edit(*, name: None = None, permissions: Optional[Union[wumpus.models.permissions.Permissions, int]] = None, color: Optional[Union[wumpus.models.color.Color, int]] = None, hoist: Optional[bool] = None, mentionable: Optional[bool] = None, reason: Optional[str] = None) wumpus.models.role.T¶
This function is a coroutine.
Modifies and edits this role. All parameters are optional and keyword-only.
- Parameters
name (str) – The new name of the role.
permissions (Union[
Permissions, int]) – The new permissions of the role.color (Union[
Color, int]) – The new color of the role.hoist (bool) – Whether or not to hoist the role.
mentionable (bool) – Whether or not to make this role mentionable.
reason (str) – The audit log reason to use.
- property id: int¶
The snowflake ID of this object.
- Type
Snowflake
- class wumpus.RoleTags(data: Dict[str, Any], /)¶
Represents the tags of a Discord role.
- bot_id¶
The ID of the bot that manages this role, if any.
- Type
Snowflake
- integration_id¶
The ID of the integration that manages this role, if any.
- Type
Snowflake
Whether or not this role is the “Nitro Booster” role.
- Type
Emoji¶
- class wumpus.PartialEmoji(*, name: str, id: Optional[int] = None, animated: bool = False, connection: Optional[wumpus.core.connection.Connection] = None)¶
Represents an emoji with basic attributes.
- property created_at: wumpus.models.objects.Timestamp¶
The creation timestamp of this object.
- Type
- classmethod from_json(payload: Dict[str, Any], /, *, connection: Optional[wumpus.core.connection.Connection] = None) wumpus.models.emoji.PT¶
Generates a
PartialEmojifrom a raw JSON payload.- Parameters
payload (dict) – The payload to use.
- Returns
The generated partial emoji object from the payload.
- Return type
- property id: int¶
The snowflake ID of this object.
- Type
Snowflake
- property image: wumpus.models.asset.Asset¶
Retrieves the
Assetthat represents this emoji.- Returns
The asset of this emoji.
- Return type
- Raises
ValueError – This asset is a unicode emoji.
- is_unicode() bool¶
Return whether or not this asset is a unicode emoji.
- Returns
Whether or not this asset is a unicode emoji.
- Return type
- classmethod parse(string: str, /, *, connection: Optional[wumpus.core.connection.Connection] = None) wumpus.models.emoji.PT¶
Parses a string that represents an emoji into a
PartialEmoji.The given string should follow one of the following formats:
<:name:id>
<a:name:id>
name:id
a:name:id
Note
This does not account for unicode emoji. (It is been considered, however)
- Parameters
string (str) – The string to parse.
- Returns
The partial emoji object representing the string.
- Return type
Asset¶
- class wumpus.Asset(connection: wumpus.core.connection.Connection, /, *, url: str, info: wumpus.models.asset.AssetInfo = AssetInfo(format=None, static_format=None, size=None), animated: bool = False, hash: Optional[str] = None)¶
Represents an image representing something inside of Discord.
- property base_url: str¶
The base URL with no extension or query parameters, that this asset uses.
- Type
- property default_format: Literal['png', 'jpg', 'jpeg', 'webp', 'gif']¶
The default format of this asset.
- Type
- replace(*, format: Optional[Literal[png, jpg, jpeg, webp, gif]] = None, size: Optional[Literal[16, 32, 64, 128, 256, 512, 1024, 2048, 4096]] = None, static_format: Optional[Literal[png, jpg, jpeg, webp]] = None) wumpus.models.asset.T¶
Return a copy of this asset with replaced attributes. All parameters are positional only and optional.
- property size: Literal[16, 32, 64, 128, 256, 512, 1024, 2048, 4096]¶
The size of this asset.
- Type
Optional[int]
- property static_format: Literal['png', 'jpg', 'jpeg', 'webp']¶
The static format of this asset.
- Type
- with_format(format: Literal[png, jpg, jpeg, webp, gif], /) wumpus.models.asset.T¶
Return a copy of this asset with the given format.
- with_size(size: Literal[16, 32, 64, 128, 256, 512, 1024, 2048, 4096], /) wumpus.models.asset.T¶
Return a copy of this asset with the given size.
Managers¶
- class wumpus.UserManager(connection: wumpus.core.connection.Connection, /, cache: Optional[Dict[int, wumpus.models.user.User]] = None)¶
- property cache: Dict[int, wumpus.core.manager.T]¶
The internal cache of this manager.
- Type
Dict[Snowflake, Any]
- async fetch(id: int, /, *, cache: bool = True) wumpus.models.user.User¶
Makes an API request to Discord to fetch a user by their snowflake ID.
- Parameters
id (Snowflake) – The user’s snowflake ID.
cache (bool = False) – Whether or not to cache the fetched user.
- Returns
The user fetched. If none was found, None is returned.
- Return type
Optional[
User]
- filter(predicate: Callable[[wumpus.core.manager.T], bool], /) Iterable[wumpus.core.manager.T]¶
Returns a filter object after filtering the internal cache with a predicate.
- Parameters
predicate (Callable[[Any], bool]) – The check predicate to use.
- Returns
- Return type
Iterable[Any]
- find(predicate: Callable[[wumpus.core.manager.T], bool], /) wumpus.core.manager.T¶
Finds an item in the internal cache by a predicate function.
- Parameters
predicate (Callable[[Any], bool]) – The check predicate to use.
- Returns
- Return type
Optional[Any]
- flatten() List[wumpus.core.manager.T]¶
Returns a list of all objects stored in the internal cache.
- Returns
- Return type
List[Any]
- get(id: int, /) wumpus.core.manager.T¶
Gets and returns an item from the internal cache by it’s snowflake ID.
- Parameters
id (Snowflake) – The ID to lookup.
- async getch(id: int, /) wumpus.models.user.User¶
Calls
UserManager.get()on the given snowflake. If no user is found in the cache,UserManager.fetch()is then called instead.This is the exact equivalent of doing:
users.get(id) or await users.fetch(id)
- Parameters
id (Snowflake) – The user’s snowflake ID.
- Returns
The user found. If none was found, None is returned.
- Return type
Optional[
User]
- has(id: int, /) bool¶
Return whether or not the internal cache is storing an object mapped to the specified snowflake ID.
- Parameters
id (Snowflake) – The ID to lookup.
- Returns
- Return type
- subset(predicate: Callable[[wumpus.core.manager.T], bool], /) wumpus.core.manager.C¶
Creates a copy of this class with a subset of the cache.
For example, Manager([1, 2, 3]).subset(lambda x: x % 2 == 1) would return Manager([1, 3]). (Note that this is not how managers are actually constructed.)
- Parameters
predicate (Callable[[Any], bool]) – The check predicate to use.
- Returns
- Return type
Any
- class wumpus.GuildManager(connection: wumpus.core.connection.Connection, /, cache: Optional[Dict[int, wumpus.models.user.User]] = None)¶
- property cache: Dict[int, wumpus.core.manager.T]¶
The internal cache of this manager.
- Type
Dict[Snowflake, Any]
- async fetch(id: int, /, *, cache: bool = True) wumpus.typings.payloads.GuildPayload¶
Makes an API request to Discord to fetch a guild by it’s snowflake ID.
- Parameters
id (Snowflake) – The guild’s snowflake ID.
cache (bool = False) – Whether or not to cache the fetched guild.
- Returns
The guild fetched. If none was found, None is returned.
- Return type
Optional[
Guild]
- filter(predicate: Callable[[wumpus.core.manager.T], bool], /) Iterable[wumpus.core.manager.T]¶
Returns a filter object after filtering the internal cache with a predicate.
- Parameters
predicate (Callable[[Any], bool]) – The check predicate to use.
- Returns
- Return type
Iterable[Any]
- find(predicate: Callable[[wumpus.core.manager.T], bool], /) wumpus.core.manager.T¶
Finds an item in the internal cache by a predicate function.
- Parameters
predicate (Callable[[Any], bool]) – The check predicate to use.
- Returns
- Return type
Optional[Any]
- flatten() List[wumpus.core.manager.T]¶
Returns a list of all objects stored in the internal cache.
- Returns
- Return type
List[Any]
- get(id: int, /) wumpus.core.manager.T¶
Gets and returns an item from the internal cache by it’s snowflake ID.
- Parameters
id (Snowflake) – The ID to lookup.
- async getch(id: int, /) wumpus.models.user.User¶
Calls
GuildManager.get()on the given snowflake. If no user is found in the cache,GuildManager.fetch()is then called instead.This is the exact equivalent of doing:
guilds.get(id) or await guilds.fetch(id)
- Parameters
id (Snowflake) – The guild’s snowflake ID.
- Returns
The guild found. If none was found, None is returned.
- Return type
Optional[
Guild]
- has(id: int, /) bool¶
Return whether or not the internal cache is storing an object mapped to the specified snowflake ID.
- Parameters
id (Snowflake) – The ID to lookup.
- Returns
- Return type
- subset(predicate: Callable[[wumpus.core.manager.T], bool], /) wumpus.core.manager.C¶
Creates a copy of this class with a subset of the cache.
For example, Manager([1, 2, 3]).subset(lambda x: x % 2 == 1) would return Manager([1, 3]). (Note that this is not how managers are actually constructed.)
- Parameters
predicate (Callable[[Any], bool]) – The check predicate to use.
- Returns
- Return type
Any
Bitfields¶
- class wumpus.Permissions(value: int = 0, /, **kwargs)¶
Represents the permissions that a member or role has.
This can be constructed using a permissions integer or by using keyword-arguments.
- class wumpus.SystemChannelFlags(value: Optional[int] = None, /)¶
- property suppress_guild_reminder_notifications: None¶
Whether or not to suppress server setup tips.
- property suppress_join_notifications: None¶
Whether or not to suppress join notifications.
Whether or not to suppress server boost notifications.
Enums¶
- class wumpus.PremiumType(value)¶
This is an enum.
Represents the type of Nitro subscription a user has.
- none¶
The user does not have Nitro.
- nitro_classic¶
The user has Nitro Classic.
- nitro¶
The user has Nitro.
- class wumpus.GuildFeature(value)¶
This is an enum.
Represents a key feature a guild has.
- animated_icon¶
Guild has access to set an animated guild icon.
- banner¶
Guild has access to set a guild banner image.
- commerce¶
Guild has access to use commerce features (i.e. create store channels).
- community¶
Guild can enable welcome screen, Membership Screening, stage channels and discovery, and receives community updates.
- discoverable¶
Guild is able to be discovered in the directory.
- featurable¶
Guild is able to be featured in the directory.
- invite_splash¶
Guild has access to set an invite splash background.
- member_verification_gate¶
Guild has enabled Membership Screening.
- news¶
Guild has access to create news channels.
- partnered¶
Guild is partnered.
- preview_enabled¶
Guild can be previewed before joining via Membership Screening or the directory.
- vanity_url¶
Guild has access to set a vanity URL.
- verified¶
Guild is verified.
- vip_regions¶
Guild has access to set 384kbps bitrate in voice (previously VIP voice servers).
- welcome_screen_enabled¶
Guild has enabled the welcome screen.
- ticketed_events_enabled¶
Guild has enabled ticketed events.
- monetization_enabled¶
Guild has enabled monetization.
- more_stickers¶
Guild has increased custom sticker slots.
- three_day_thread_archive¶
Guild has access to the three day archive time for threads.
- seven_day_thread_archive¶
Guild has access to the seven day archive time for threads.
- private_threads¶
Guild has access to create private threads.
Errors¶
- exception wumpus.errors.Forbidden(response: aiohttp.client_reqrep.ClientResponse, /, *, json: Optional[Dict[str, Any]] = None, message: Optional[str] = None)¶
Raised when you are missing permissions for a certain action.
- exception wumpus.errors.HTTPError(response: aiohttp.client_reqrep.ClientResponse, /, *, json: Optional[Dict[str, Any]] = None, message: Optional[str] = None)¶
Something unexpected happened when trying to make a request.
- exception wumpus.errors.InternalServerError(response: aiohttp.client_reqrep.ClientResponse, /, *, json: Optional[Dict[str, Any]] = None, message: Optional[str] = None)¶
Something went wrong inside of Discord, internally.
- exception wumpus.errors.NotFound(response: aiohttp.client_reqrep.ClientResponse, /, *, json: Optional[Dict[str, Any]] = None, message: Optional[str] = None)¶
What you requested for is not found.
- exception wumpus.errors.Unauthorized(response: aiohttp.client_reqrep.ClientResponse, /)¶
You are not authorized, this should only be raised when you regenerate your token during runtime.
- exception wumpus.errors.WumpusError¶
The base :class`Exception` that all errors related to this library inherit from. This can techinically be used to handle all errors raised by by this library.