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 theEventHandler
onClient.events
.@cl.event("ready") async def loaded(ctx: EventContext): print("Bot logged in.")
Parameters: -
await
change_status
(game=None, status=<Status.ONLINE: 'online'>, afk=False, shard_id=0)[source]¶ Changes the bot’s current status.
Parameters:
-
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: Return type: 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: Return type: 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: Return type: 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:
-
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
-
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_invite
(invite_code, *, with_counts=True)[source]¶ Gets an invite by code.
Parameters: Return type: Returns: A new
Invite
object.
-
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_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_ready
(ctx)[source]¶ Handles a READY event, dispatching a
shards_ready
event when all shards are ready.
-
run
(*, shard_count=1, autoshard=True, **kwargs)[source]¶ Convenience method to run the bot with multio.
Parameters:
-
await
run_async
(*, shard_count=1, autoshard=True)[source]¶ Runs the client asynchronously.
Parameters:
-
await
start
(shard_count)[source]¶ Starts the bot.
Parameters: shard_count ( int
) – The number of shards to boot.
-
await
wait_for
(*args, **kwargs)[source]¶ Shortcut for
EventManager.wait_for()
.Return type: Any
-
await