curious.core.client

The main client class.

This contains a definition for Client which is used to interface primarily with Discord.

Classes

BotType An enum that signifies what type of bot this bot is.
Client(token, *, state_klass, bot_type) The main client class.
class curious.core.client.BotType[source]

Bases: enum.IntEnum

An enum that signifies what type of bot this bot is.

This will tell the commands handling how to respond, as well as how to log in.

class curious.core.client.Client(token: str, *, state_klass: type = None, bot_type: int = 9)[source]

Bases: object

The main client class. This is used to interact with Discord.

To start, you can create an instance of the client by passing it the token you want to use:

cl = Client("my.token.string")

Registering events can be done with the Client.event() decorator, or alternatively manual usage of the EventHandler on Client.events.

@cl.event("ready")
async def loaded(ctx: EventContext):
    print("Bot logged in.")
Parameters:
  • token (str) – The current token for this bot.
  • state_klass (Optional[type]) – The class to construct the connection state from.
  • bot_type (int) – A union of BotType that defines the type of this bot.
await _background_get_app_info()[source]

Gets the application info in the background.

await change_status(game=None, status=<Status.ONLINE: 'online'>, afk=False, shard_id=0)[source]

Changes the bot’s current status.

Parameters:
  • game (Optional[Game]) – The game object to use. None for no game.
  • status (Status) – The new status. Must be a Status object.
  • afk (bool) – Is the bot AFK? Only useful for userbots.
  • shard_id (int) – The shard to change your status on.
await clean_content(content)[source]

Cleans the content of a message, using the bot’s cache.

Parameters:content (str) – The content to clean.
Return type:str
Returns:The cleaned up message.
await download_channels(guild_id)[source]

Downloads all the Channel for a Guild.

Parameters:guild_id (int) – The ID of the guild to download channels for.
Return type:List[Channel]
Returns:An iterable of Channel objects.
await download_guild(guild_id, *, full=False)[source]

Downloads a Guild over HTTP.

Warning

If full is True, this will fetch and fill ALL objects of the guild, including channels and members. This can take a long time if the guild is large.

Parameters:
  • guild_id (int) – The ID of the Guild object to download.
  • full (bool) – If all extra data should be downloaded alongside it.
Return type:

Guild

Returns:

The Guild object downloaded.

await download_guild_member(guild_id, member_id)[source]

Downloads a Member over HTTP.

Warning

The Member.roles and similar fields will be empty when downloading a Member, unless the guild was in cache.

Parameters:
  • guild_id (int) – The ID of the guild which the member is in.
  • member_id (int) – The ID of the member to get.
Return type:

Member

Returns:

The Member object downloaded.

await download_guild_members(guild_id, *, after=None, limit=1000, get_all=True)[source]

Downloads the members for a Guild over HTTP.

Warning

This can take a long time on big guilds.

Parameters:
  • guild_id (int) – The ID of the guild to download members for.
  • after (Optional[int]) – The member ID after which to get members for.
  • limit (int) – The maximum number of members to return. By default, this is 1000 members.
  • get_all (bool) – Should all members be fetched?
Return type:

Iterable[Member]

Returns:

An iterable of Member.

await edit_avatar(path)[source]

A higher-level way to change your avatar. This allows you to provide a path to the avatar file instead of having to read it in manually.

Parameters:path (str) – The path-like object to the avatar file.
await edit_profile(*, username=None, avatar=None, password=None)[source]

Edits the profile of this bot.

The user is not edited in-place - instead, you must wait for the USER_UPDATE event to be fired on the websocket.

Parameters:
  • username (Optional[str]) – The new username of the bot.
  • avatar (Optional[bytes]) – The bytes-like object that represents the new avatar you wish to use.
  • password (Optional[str]) – The password to use. Only for user accounts.
event(name)[source]

A convenience decorator to mark a function as an event.

This will copy it to the events dictionary, where it will be used as an event later on.

@bot.event("message_create")
async def something(ctx, message: Message):
    pass
Parameters:name (str) – The name of the event.
events_handled

A collections.Counter of all events that have been handled since the bot’s bootup. This can be used to track statistics for events.

@command()
async def events(self, ctx: Context):
    '''
    Shows the most common events.
    '''
    
    ev = ctx.bot.events_handled.most_common(3)
    await ctx.channel.messages.send(", ".join("{}: {}".format(*x) for x in ev)
Return type:Counter
find_channel(channel_id)[source]

Finds a channel by channel ID.

await fire_event(event_name, *args, **kwargs)[source]

Fires an event.

This actually passes the arguments to EventManager.fire_event().

classmethod from_token()[source]

Starts a bot from a token object.

Parameters:token (Optional[str]) – The token to use for the bot.
gateways
Return type:Mapping[int, GatewayHandler]
Returns:A read-only view of the current gateways for this client.
await get_application(application_id)[source]

Gets an application by ID.

Parameters:application_id (int) – The client ID of the application to fetch.
Return type:AppInfo
Returns:A new AppInfo object corresponding to the application.
await get_gateway_url()[source]
Return type:str
Returns:The gateway URL for this bot.
await get_invite(invite_code, *, with_counts=True)[source]

Gets an invite by code.

Parameters:
  • invite_code (str) – The invite code to get.
  • with_counts (bool) – Return the approximate counts for this invite?
Return type:

Invite

Returns:

A new Invite object.

await get_shard_count()[source]
Return type:int
Returns:The shard count recommended for this bot.
await get_user(user_id)[source]

Gets a user by ID.

Parameters:user_id (int) – The ID of the user to get.
Return type:User
Returns:A new User object.
await get_webhook(webhook_id)[source]

Gets a webhook by ID.

Parameters:webhook_id (int) – The ID of the webhook to get.
Return type:Webhook
Returns:A new Webhook object.
await get_widget(guild_id)[source]

Gets a widget from a guild.

Parameters:guild_id (int) – The ID of the guild to get the widget of.
Return type:Widget
Returns:A Widget object.
guilds
Return type:Mapping[int, Guild]
Returns:A mapping of int -> Guild that this client can see.
guilds_for(shard_id)[source]

Gets the guilds for this shard.

Parameters:shard_id (int) – The shard ID to get guilds from.
Return type:Iterable[Guild]
Returns:A list of Guild that client can see on the specified shard.
await handle_dispatches(ctx, name, dispatch)[source]

Handles dispatches for the client.

await handle_ready(ctx)[source]

Handles a READY event, dispatching a shards_ready event when all shards are ready.

await handle_shard(shard_id, shard_count)[source]

Handles a shard.

Parameters:
  • shard_id (int) – The shard ID to boot and handle.
  • shard_count (int) – The shard count to send in the identify packet.
invite_url
Return type:str
Returns:The invite URL for this bot.
await kill()[source]

Kills the bot by closing all shards.

Return type:None
run(*, shard_count=1, autoshard=True, **kwargs)[source]

Convenience method to run the bot with multio.

Parameters:
  • shard_count (int) – The number of shards to use. Ignored if autoshard is True.
  • autoshard (bool) – If the bot should be autosharded.
await run_async(*, shard_count=1, autoshard=True)[source]

Runs the client asynchronously.

Parameters:
  • shard_count (int) – The number of shards to boot.
  • autoshard (bool) – If the bot should be autosharded.
await start(shard_count)[source]

Starts the bot.

Parameters:shard_count (int) – The number of shards to boot.
user
Return type:BotUser
Returns:The User that this client is logged in as.
await wait_for(*args, **kwargs)[source]

Shortcut for EventManager.wait_for().

Return type:Any