curious.core.httpclient¶
The main Discord HTTP interface.
Functions
encode_multipart (fields, files[, boundary]) |
Encode dict of form fields and dict of files as multipart/form-data. |
parse_date_header (header) |
Parses a date header. |
Classes
Endpoints (base_url) |
|
||
HTTPClient (token, *, bot, max_connections) |
The HTTP client object used to make requests to Discord’s servers. |
-
class
curious.core.httpclient.
HTTPClient
(token: str, *, bot: bool = True, max_connections: int = 10)[source]¶ Bases:
object
The HTTP client object used to make requests to Discord’s servers.
If a particular method is not listed here, you can use one of the five following methods to make a manual request:
All of these functions require a ratelimit bucket which will be used to prevent the client from hitting 429 ratelimits.
Parameters: -
await
_make_request
(*args, **kwargs)[source]¶ Makes a request via the current session.
Return type: Response
Returns: The response body.
-
await
add_member_role
(guild_id, member_id, role_id)[source]¶ Adds a single role to a member.
If you want to add multiple roles to a member, use
add_roles()
.Parameters:
Authorize a bot to be added to a guild.
Warning
This is a user-acount only endpoint.
Parameters:
-
await
ban_user
(guild_id, user_id, delete_message_days=7, reason=None)[source]¶ Bans a user from a guild.
Parameters:
-
await
change_nickname
(guild_id, nickname, *, member_id=None, me=False)[source]¶ Changes the nickname of a member.
If me is True, then member_id is not required. Otherwise, member_id is required.
Parameters:
-
await
create_channel
(guild_id, name, type, *, bitrate=None, user_limit=None, permission_overwrites=None)[source]¶ Creates a new channel.
Parameters: - guild_id (
int
) – The guild ID to create the channel in. - name (
str
) – The name of the channel. - type (
int
) – The type of the channel (text/voice). - bitrate (
Optional
[int
]) – The bitrate of the channel, if it is a voice channel. - user_limit (
Optional
[int
]) – The maximum number of users that can be in the channel. - permission_overwrites (
Optional
[list
]) – The list of permission overwrites to use for this channel.
- guild_id (
-
await
create_guild
(name, region=None, icon=None, verification_level=None, default_message_notifications=None, roles=None, channels=None)[source]¶ Creates a new guild.
Parameters: - name (
str
) – The name of the new guild. - region (
Optional
[str
]) – The region of the new guild. - icon (
Optional
[str
]) – The base64 icon of the new guild. - verification_level (
Optional
[int
]) – The verification level of the new guild. - default_message_notifications (
Optional
[int
]) – The default notification level of the new guild. - roles (
Optional
[List
[dict
]]) – A dict of role objects. - channels (
Optional
[List
[dict
]]) – A dict of channel objects.
- name (
-
await
create_guild_emoji
(guild_id, *, name, image, roles=None)[source]¶ Creates an emoji in a guild.
Parameters:
-
await
create_invite
(channel_id, *, max_age=None, max_uses=None, temporary=None, unique=None)[source]¶ Creates an invite.
Parameters:
-
await
create_private_channel
(user_id)[source]¶ Opens a new private channel with a user.
Parameters: user_id ( int
) – The user ID of the user to open with.
-
await
create_role
(guild_id)[source]¶ Creates a role in a guild.
Parameters: guild_id ( int
) – The guild to create the role in.Return type: dict
-
await
delete_all_reactions
(channel_id, message_id)[source]¶ Removes all reactions from a message.
Parameters:
-
await
delete_channel
(channel_id)[source]¶ Deletes a channel.
Parameters: channel_id ( int
) – The channel ID to delete.
-
await
delete_invite
(invite_code)[source]¶ Deletes the invite specified by the code.
Parameters: invite_code ( str
) – The code of the invite to delete.
-
await
delete_message
(channel_id, message_id)[source]¶ Deletes a message.
This requires the MANAGE_MESSAGES permission.
Parameters:
-
await
delete_multiple_messages
(channel_id, message_ids)[source]¶ Deletes multiple messages.
This will silently discard any messages that don’t exist.
This requires MANAGE_MESSAGES on the channel, regardless of what messages are being deleted.
Parameters:
-
await
delete_reaction
(channel_id, message_id, emoji, victim=None)[source]¶ Deletes a reaction from a message.
Parameters:
-
await
delete_webhook
(webhook_id)[source]¶ Deletes a webhook.
Parameters: webhook_id ( int
) – The ID of the webhook to delete.
-
await
delete_webhook_with_token
(webhook_id, token)[source]¶ Deletes a webhook with a token.
Parameters:
-
await
edit_channel
(channel_id, *, name=None, position=None, topic=None, bitrate=None, user_limit=-1)[source]¶ Edits a channel.
Parameters: - channel_id (
int
) – The channel ID to edit. - name (
Optional
[str
]) – The new name of the channel. - position (
Optional
[int
]) – The new position of the channel. - topic (
Optional
[str
]) – The new topic of the channel. - bitrate (
Optional
[int
]) – The new bitrate of the channel. - user_limit (
int
) – The user limit of the channel.
- channel_id (
-
await
edit_guild
(guild_id, *, name=None, icon_content=None, region=None, verification_level=None, default_message_notifications=None, afk_channel_id=None, afk_timeout=None, splash_content=None, explicit_content_filter=None, system_channel_id=None)[source]¶ Modifies a guild.
See https://discordapp.com/developers/docs/resources/guild#modify-guild for the fields available.
-
await
edit_guild_emoji
(guild_id, emoji_id, *, name=None, roles=None)[source]¶ Modifies an emoji in a guild.
Parameters:
-
await
edit_member_roles
(guild_id, member_id, role_ids)[source]¶ Modifies the roles that a member object contains.
Parameters:
-
await
edit_member_voice_state
(guild_id, member_id, *, deaf=None, mute=None, channel_id=None)[source]¶ Edits the voice state of a member.
Parameters:
-
await
edit_message
(channel_id, message_id, content=None, embed=None)[source]¶ Edits a message.
This will only work on your own messages.
Parameters:
-
await
edit_overwrite
(channel_id, target_id, type_, *, allow=0, deny=0)[source]¶ Modifies or adds an overwrite.
Parameters:
-
await
edit_role
(guild_id, role_id, name=None, permissions=None, position=None, colour=None, hoist=None, mentionable=None)[source]¶ Edits a role.
Parameters: - guild_id (
int
) – The guild ID that contains the role. - role_id (
int
) – The role ID to edit. - name (
Optional
[str
]) – The new name of the role. - permissions (
Optional
[int
]) – The new permissions for the role. - position (
Optional
[int
]) – The position for the role. - colour (
Optional
[int
]) – The colour for the role. - hoist (
Optional
[bool
]) – Is this role hoisted? - mentionable (
Optional
[bool
]) – Is this role mentionable?
- guild_id (
-
await
edit_role_positions
(guild_id, role_mapping)[source]¶ Changes the position of a set of roles.
Parameters:
-
await
edit_user
(username=None, avatar=None, password=None)[source]¶ Edits the profile of the bot.
Parameters:
-
await
edit_webhook_with_token
(webhook_id, token, *, name=None, avatar=None)[source]¶ Edits a webhook, with a token.
Parameters:
-
await
edit_widget
(guild_id, enabled=None, channel_id=0)[source]¶ Edits the widget status for this guild.
Parameters:
-
await
execute_webhook
(webhook_id, webhook_token, *, content=None, embeds=None, username=None, avatar_url=None, wait=False)[source]¶ Executes a webhook.
Parameters: - webhook_id (
int
) – The ID of the webhook to execute. - webhook_token (
str
) – The token of this webhook. - content (
Optional
[str
]) – Any message content to send. - embeds (
Optional
[List
[Dict
[~KT, ~VT]]]) – A list of embeds to send. - username (
Optional
[str
]) – The username to override with. - avatar_url (
Optional
[str
]) – The avatar URL to send. - wait (
bool
) – If we should wait for the message to send.
- webhook_id (
-
await
get_app_info
(application_id)[source]¶ Gets some basic info about an application.
Parameters: application_id ( Optional
[int
]) – The ID of the application to get info about. If this is None, it will fetch the current application info.
-
await
get_application
(application_id)[source]¶ Gets an application by ID.
Parameters: application_id ( int
) – The ID of the application to get.
-
await
get_audit_logs
(guild_id, *, limit=50, user_id=None, action_type=None)[source]¶ Gets the audit log for this guild.
Parameters:
Gets authorized apps for this account.
Warning
This is a user-account only endpoint.
-
await
get_bans
(guild_id)[source]¶ Gets a list of bans from a guild.
Parameters: guild_id ( int
) – The guild to get bans from.Returns: A list of user dicts containing ban information.
-
await
get_channel
(channel_id)[source]¶ Gets a channel.
Parameters: channel_id ( int
) – The channel ID to get.
-
await
get_gateway_url
()[source]¶ It is not recommended to use this method - use
HTTPClient.get_shard_count()
instead. That method provides the gateway URL as well.Returns: The websocket gateway URL to get.
-
await
get_guild
(guild_id)[source]¶ Gets a guild by guild ID.
Parameters: guild_id ( int
) – The ID of the guild to get.Returns: A guild object.
-
await
get_guild_channels
(guild_id)[source]¶ Gets a list of channels in a guild.
Parameters: guild_id ( int
) – The ID of the guild to get.Returns: A list of channel objects.
-
await
get_guild_emojis
(guild_id)[source]¶ Gets the emojis for a guild.
Parameters: guild_id ( int
) – The guild ID to get emojis for.
-
await
get_guild_members
(guild_id, *, limit=None, after=None)[source]¶ Gets guild members for the specified guild.
Parameters:
-
await
get_invites_for
(guild_id)[source]¶ Gets the invites for the specified guild.
Parameters: guild_id ( int
) – The guild ID to get invites inside.
-
await
get_mentions
(*, guild_id=None, limit=25, roles=True, everyone=True)[source]¶ Gets your recent mentions.
Warning
This is a user-acount only endpoint.
Parameters:
-
await
get_message
(channel_id, message_id)[source]¶ Gets a single message from the channel.
Parameters: Returns: The message data.
-
await
get_message_history
(channel_id, *, before=None, after=None, around=None, limit=100)[source]¶ Gets a list of messages from a channel.
This requires READ_MESSAGES on the channel.
Parameters: Returns: A list of message dictionaries.
-
await
get_pins
(channel_id)[source]¶ Gets the pins for a channel.
Parameters: channel_id ( int
) – The channel ID to get pins from.
-
get_ratelimit_lock
(bucket)[source]¶ Gets a ratelimit lock from the dict if it exists, otherwise creates a new one.
Return type: Lock
-
await
get_reaction_users
(channel_id, message_id, emoji)[source]¶ Gets a list of users who reacted to this message with the specified reaction.
Parameters:
-
staticmethod
get_response_data
()[source]¶ Return either the text of a request or the JSON.
Parameters: response ( Response
) – The response to use.Return type: Union
[str
,dict
]
-
await
get_user
(user_id)[source]¶ Gets a user from a user ID.
Parameters: user_id ( int
) – The ID of the user to fetch.Returns: A user dictionary.
-
await
get_vanity_url
(guild_id)[source]¶ Gets the vanity URL for a guild.
Parameters: guild_id ( int
) – The guild ID to get the vanity URL of.
-
await
get_webhook
(webhook_id)[source]¶ Gets a webhook object for the specified ID.
Parameters: webhook_id ( int
) – The ID of the webhook to get.
-
await
get_webhooks_for_channel
(channel_id)[source]¶ Gets the webhooks for the specified channel.
Parameters: channel_id ( int
) – The ID of the channel to get the webhooks for.
-
await
get_webhooks_for_guild
(guild_id)[source]¶ Gets the webhooks for the specified guild.
Parameters: guild_id ( int
) – The ID of the guild to get the webhooks for.
-
await
get_widget_data
(guild_id)[source]¶ Gets the current widget data for a guild.
Parameters: guild_id ( int
) – The guild ID of the widget to fetch.
-
await
get_widget_status
(guild_id)[source]¶ Gets the current widget status information for a guild.
Parameters: guild_id ( int
) – The guild ID to fetch.
-
await
leave_guild
(guild_id)[source]¶ Leaves a guild.
Parameters: guild_id ( str
) – The guild ID of the guild to leave.
-
await
request
(bucket, *args, **kwargs)[source]¶ Makes a rate-limited request.
This will respect Discord’s X-Ratelimit-Limit headers to make requests.
Parameters: bucket ( object
) – The bucket this request falls under.
Revokes an application authorization.
Warning
This is a user-acount only endpoint.
Parameters: app_id ( int
) – The ID of the application to revoke the authorization of.
-
await
send_file
(channel_id, file_content, *, filename=None, content=None)[source]¶ Uploads a file to the current channel.
This will encode the data as multipart/form-data.
Parameters:
-
await
send_message
(channel_id, content, tts=False, embed=None)[source]¶ Sends a message to a channel.
Parameters:
-
await
send_typing
(channel_id)[source]¶ Starts typing in a channel.
Parameters: channel_id ( str
) – The ID of the channel to type in.
-
await
-
curious.core.httpclient.
encode_multipart
(fields, files, boundary=None)[source]¶ Encode dict of form fields and dict of files as multipart/form-data. Return tuple of (body_string, headers_dict). Each value in files is a dict with required keys ‘filename’ and ‘content’, and optional ‘mimetype’ (if not specified, tries to guess mime type or uses ‘application/octet-stream’). >>> body, headers = encode_multipart({‘FIELD’: ‘VALUE’}, … {‘FILE’: {‘filename’: ‘F.TXT’, ‘content’: ‘CONTENT’}}, … boundary=’BOUNDARY’) >>> print(‘n’.join(repr(l) for l in body.split(‘rn’))) ‘–BOUNDARY’ ‘Content-Disposition: form-data; name=”FIELD”’ ‘’ ‘VALUE’ ‘–BOUNDARY’ ‘Content-Disposition: form-data; name=”FILE”; filename=”F.TXT”’ ‘Content-Type: text/plain’ ‘’ ‘CONTENT’ ‘–BOUNDARY–’ ‘’ >>> print(sorted(headers.items())) [(‘Content-Length’, ‘193’), (‘Content-Type’, ‘multipart/form-data; boundary=BOUNDARY’)] >>> len(body) 193 Copied from: https://code.activestate.com/recipes/578668-encode-multipart-form-data-for-uploading-files-via/
-
curious.core.httpclient.
parse_date_header
(header)[source]¶ Parses a date header.
Parameters: header ( str
) – The contents of the header to parse.Return type: datetime
Returns: A datetime.datetime
that corresponds to the date header.