curious.dataclasses.channel¶
Wrappers for Channel objects.
Classes
Channel (client, **kwargs) |
Represents a channel object. |
ChannelMessageWrapper (channel) |
Represents a channel’s message container. |
ChannelType |
Returns a mapping from Discord channel type. |
HistoryIterator (channel, max_messages, *, …) |
An iterator that allows you to automatically fetch messages and async iterate over them. |
-
class
curious.dataclasses.channel.
Channel
(client, **kwargs) → None[source]¶ Bases:
curious.dataclasses.bases.Dataclass
Represents a channel object.
Inspects the stack to ensure we’re being called correctly.
-
_update_overwrites
(overwrites)[source]¶ Updates the overwrites for this channel.
Parameters: overwrites ( List
[dict
]) – A list of overwrite dicts.
-
await
change_overwrite
(overwrite)[source]¶ Changes an overwrite for this channel.
This overwrite must be an instance of
Overwrite
.Parameters: overwrite ( Overwrite
) – The specific overwrite to use. If this is None, the overwrite will be deleted.
-
await
create_invite
(**kwargs)[source]¶ Creates an invite in this channel.
Parameters: - max_age – The maximum age of the invite.
- max_uses – The maximum uses of the invite.
- temporary – Is this invite temporary?
- unique – Is this invite unique?
Return type:
-
await
create_webhook
(*, name=None, avatar=None)[source]¶ Create a webhook in this channel.
Parameters: Return type: Returns: A
Webhook
that represents the webhook created.
-
await
delete_messages
(messages)[source]¶ This function is deprecated since 0.7.0. See
Channel.messages.delete_messages()
instead. It will be removed at version 0.9.0.Deletes messages from a channel. This is the low-level delete function - for the high-level function, see
Channel.purge()
.Example for deleting all the last 100 messages:
history = channel.get_history(limit=100) messages = [] async for message in history: messages.append(message) await channel.delete_messages(messages)
Parameters: messages ( List
[Message
]) – A list ofMessage
objects to delete.Return type: int
Returns: The number of messages deleted.
-
await
delete_webhook
(webhook)[source]¶ Deletes a webhook.
You must have MANAGE_WEBHOOKS to delete this webhook.
Parameters: webhook ( Webhook
) – TheWebhook
to delete.Return type: Webhook
-
await
edit_webhook
(webhook, *, name=None, avatar=None)[source]¶ Edits a webhook.
Parameters: Return type: Returns: The modified
Webhook
. object.
-
get_by_name
(name)[source]¶ Gets a channel by name in this channel’s children.
Parameters: name ( str
) – The name of the channel to get.Return type: Optional
[Channel
]Returns: A Channel
if the channel was find
-
get_history
(before=None, after=None, limit=100)[source]¶ This function is deprecated since 0.7.0. See
Channel.messages.get_history()
instead. It will be removed at version 0.9.0.Gets history for this channel.
This is not an async function - it returns a
HistoryIterator
which can be async iterated over to get message history.async for message in channel.get_history(limit=1000): print(message.content, "by", message.author.user.name)
Parameters: Return type:
-
await
get_message
(message_id)[source]¶ This function is deprecated since 0.7.0. See
Channel.messages.get()
instead. It will be removed at version 0.9.0.Gets a single message from this channel.
Parameters: message_id ( int
) – The message ID to retrieve.Return type: Message
Returns: A new Message
object.
-
await
get_pins
()[source]¶ Gets the pins for a channel.
Return type: List
[Message
]Returns: A list of Message
objects.
-
await
get_webhooks
()[source]¶ Gets the webhooks for this channel.
Return type: List
[Webhook
]Returns: A list of Webhook
objects for the channel.
-
history
¶ This function is deprecated since 0.7.0. See
Channel.messages()
instead. It will be removed at version 0.9.0.Return type: HistoryIterator
Returns: A HistoryIterator
that can be used to iterate over the channel history.
-
messages
¶ Return type: ChannelMessageWrapper
Returns: The ChannelMessageWrapper
for this channel, if applicable.
-
overwrites
¶ Return type: Mapping
[int
,Overwrite
]Returns: A mapping of target_id -> Overwrite
for this channel.
-
owner
¶ Return type: Optional
[User
]Returns: If this channel is a group channel, the owner of the channel.
-
parent
¶ Return type: Optional
[Channel
]Returns: If this channel has a parent, the parent category of this channel.
-
permissions
(obb)[source]¶ Gets the permission overwrites for the specified object.
Return type: Overwrite
-
pins
¶ Return type: AsyncIterator
[Message
]Returns: A AsyncIteratorWrapper
that can be used to iterate over the pins.
-
await
purge
(limit=100, *, author=None, content=None, predicate=None, fallback_from_bulk=False)[source]¶ This function is deprecated since 0.7.0. See
Channel.messages.purge()
instead. It will be removed at version 0.9.0.Purges messages from a channel. This will attempt to use
bulk-delete
if possible, but otherwise will use the normal delete endpoint (which can get ratelimited severely!) iffallback_from_bulk
is True.Example for deleting all messages owned by the bot:
me = channel.guild.me await channel.purge(limit=100, author=me)
Custom check functions can also be applied which specify any extra checks. They take one argument (the Message object) and return a boolean (True or False) determining if the message should be deleted.
For example, to delete all messages with the letter
i
in them:await channel.purge(limit=100, predicate=lambda message: 'i' in message.content)
Parameters: - limit (
int
) – The maximum amount of messages to delete. -1 for unbounded size. - author (
Optional
[Member
]) – Only delete messages made by this author. - content (
Optional
[str
]) – Only delete messages that exactly match this content. - predicate (
Optional
[Callable
[[Message
],bool
]]) – A callable that determines if a message should be deleted. - fallback_from_bulk (
bool
) – If this is True, messages will be regular deleted if they cannot be bulk deleted.
Returns: The number of messages deleted.
- limit (
-
recipients
¶ Return type: Mapping
[int
,User
]Returns: A mapping of int -> User
for the recipients of this private chat.
-
await
send
(content=None, *, tts=False, embed=None)[source]¶ This function is deprecated since 0.7.0. See
Channel.messages.send()
instead. It will be removed at version 0.10.0.Sends a message to this channel.
This requires SEND_MESSAGES permission in the channel. If the content is not a string, it will be automatically stringified.
await channel.send("Hello, world!")
Parameters: Return type: Returns: A new
Message
object.
-
await
send_file
(file_content, filename, *, message_content=None)[source]¶ This function is deprecated since 0.7.0. See
Channel.messages.upload()
instead. It will be removed at version 0.10.0.Uploads a message to this channel.
This requires SEND_MESSAGES and ATTACH_FILES permission in the channel.
with open("/tmp/emilia_best_girl.jpg", 'rb') as f: await channel.send_file(f.read(), "my_waifu.jpg")
Parameters: Return type: Returns: The new
Message
created.
-
typing
¶ Return type: AsyncContextManager
[None
]Returns: A context manager that sends typing repeatedly. Usage:
async with channel.typing: res = await do_long_action() await channel.messages.send("Long action:", res)
-
await
upload_file
(filename, *, message_content=None)[source]¶ This function is deprecated since 0.7.0. See
Channel.messages.upload()
instead. It will be removed at version 0.10.0.A higher level interface to
send_file
.This allows you to specify one of the following to upload:
- A filename (str)
- A file-like object
- A path-like object
This will open the file, read it in binary, and upload it to the channel.
Parameters: Return type: Returns: The new
Message
created.
-
user
¶ Return type: Optional
[User
]Returns: If this channel is a private channel, the User
of the other user.
-
webhooks
¶ Return type: AsyncIterator
[Webhook
]Returns: A AsyncIteratorWrapper
for theWebhook
objects in this channel.
-
-
class
curious.dataclasses.channel.
ChannelMessageWrapper
(channel: curious.dataclasses.channel.Channel)[source]¶ Bases:
object
Represents a channel’s message container.
-
await
bulk_delete
(messages)[source]¶ Deletes messages from a channel. This is the low-level delete function - for the high-level function, see
Channel.messages.purge()
.Example for deleting all the last 100 messages:
history = channel.messages.get_history(limit=100) messages = [] async for message in history: messages.append(message) await channel.messages.bulk_delete(messages)
Parameters: messages ( List
[Message
]) – A list ofMessage
objects to delete.Return type: int
Returns: The number of messages deleted.
-
await
get
(message_id)[source]¶ Gets a single message from this channel.
Changed in version 0.7.0: Errors raised are now consistent across bots and userbots.
Parameters: message_id ( int
) – The message ID to retrieve.Return type: Message
Returns: A new Message
object.Raises: CuriousError – If the message could not be found.
-
get_history
(before=None, after=None, limit=100)[source]¶ Gets history for this channel.
This is not an async function - it returns a
HistoryIterator
which can be async iterated over to get message history.async for message in channel.get_history(limit=1000): print(message.content, "by", message.author.user.name)
Parameters: Return type:
-
history
¶ Return type: HistoryIterator
Returns: A HistoryIterator
that can be used to iterate over the channel history.
-
await
purge
(limit=100, *, author=None, content=None, predicate=None, fallback_from_bulk=False)[source]¶ Purges messages from a channel. This will attempt to use
bulk-delete
if possible, but otherwise will use the normal delete endpoint (which can get ratelimited severely!) iffallback_from_bulk
is True.Example for deleting all messages owned by the bot:
me = channel.guild.me await channel.messages.purge(limit=100, author=me)
Custom check functions can also be applied which specify any extra checks. They take one argument (the Message object) and return a boolean (True or False) determining if the message should be deleted.
For example, to delete all messages with the letter
i
in them:await channel.messages.purge(limit=100, predicate=lambda message: 'i' in message.content)
Parameters: - limit (
int
) – The maximum amount of messages to delete. -1 for unbounded size. - author (
Optional
[Member
]) – Only delete messages made by this author. - content (
Optional
[str
]) – Only delete messages that exactly match this content. - predicate (
Optional
[Callable
[[Message
],bool
]]) – A callable that determines if a message should be deleted. - fallback_from_bulk (
bool
) – If this is True, messages will be regular deleted if they cannot be bulk deleted.
Returns: The number of messages deleted.
- limit (
-
await
send
(content=None, *, tts=False, embed=None)[source]¶ Sends a message to this channel.
This requires SEND_MESSAGES permission in the channel. If the content is not a string, it will be automatically stringified.
await channel.send("Hello, world!")
Parameters: Return type: Returns: A new
Message
object.
-
await
upload
(fp, *, filename=None, message_content=None)[source]¶ Uploads a message to this channel.
This requires SEND_MESSAGES and ATTACH_FILES permission in the channel.
with open("/tmp/emilia_best_girl.jpg", 'rb') as f: await channel.messages.upload(f, "my_waifu.jpg")
Parameters: - fp (
Union
[bytes
,str
,PathLike
,IO
[AnyStr
]]) –Variable.
- If passed a string or a
os.PathLike
, will open and read the file and
upload it. - If passed bytes, will use the bytes as the file content. - If passed a file-like, will read and use the content to upload.
- If passed a string or a
- filename (
Optional
[str
]) – The filename for the file uploaded. If a path-like or str is passed, will use the filename from that if this is not specified. - message_content (
Optional
[str
]) – Optional: Any extra content to be sent with the message.
Return type: Returns: The new
Message
created.- fp (
-
await
-
class
curious.dataclasses.channel.
ChannelType
[source]¶ Bases:
enum.IntEnum
Returns a mapping from Discord channel type.
-
class
curious.dataclasses.channel.
HistoryIterator
(channel: curious.dataclasses.channel.Channel, max_messages: int = -1, *, before: int = None, after: int = None)[source]¶ Bases:
collections.abc.AsyncIterator
An iterator that allows you to automatically fetch messages and async iterate over them.
it = HistoryIterator(some_channel, bot, max_messages=100) # usage 1 async for message in it: ... # usage 2 await it.fill_messages() for message in it.messages: ...
Note that usage 2 will only fill chunks of 100 messages at a time.
Parameters: Changed in version 0.7.0: Removed the
client
parameter.