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.
children
Return type:List[Channel]
Returns:A list of Channel children this channel has, if any.
await connect()[source]

Connects to voice in this channel.

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:

Invite

await create_webhook(*, name=None, avatar=None)[source]

Create a webhook in this channel.

Parameters:
  • name (Optional[str]) – The name of the new webhook.
  • avatar (Optional[bytes]) – The bytes content of the new webhook.
Return type:

Webhook

Returns:

A Webhook that represents the webhook created.

await delete()[source]

Deletes this channel.

Return type:Channel
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 of Message 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) – The Webhook to delete.
Return type:Webhook
await edit(**kwargs)[source]

Edits this channel.

Return type:Channel
await edit_webhook(webhook, *, name=None, avatar=None)[source]

Edits a webhook.

Parameters:
Return type:

Webhook

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:
  • limit (int) – The maximum number of messages to get.
  • before (Optional[int]) – The snowflake ID to get messages before.
  • after (Optional[int]) – The snowflake ID to get messages after.
Return type:

HistoryIterator

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.
guild
Return type:Optional[Guild]
Returns:The Guild associated with this 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.
icon_url
Return type:Optional[str]
Returns:The icon URL for this channel if it is a group DM.
me_permissions
Return type:Overwrite
Returns:The overwrite permissions for the current member.
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.
private
Return type:bool
Returns:If this channel is a private channel (i.e has no guild.)
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!) if fallback_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.

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:
  • content (Optional[str]) – The content of the message to send.
  • tts (bool) – Should this message be text to speech?
  • embed (Optional[Embed]) – An embed object to send with this message.
Return type:

Message

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:
  • file_content (bytes) – The bytes-like file content to upload. This cannot be a file-like object.
  • filename (str) – The filename of the file.
  • message_content (Optional[str]) – Optional: Any extra content to be sent with the message.
Return type:

Message

Returns:

The new Message created.

await send_typing()[source]

Starts typing in the channel for 5 seconds.

Return type:None
snowflake_timestamp
Return type:datetime
Returns:The timestamp of the snowflake.
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:
  • filename (str) – The file to send, in the formats specified above.
  • message_content (Optional[str]) – Any extra content to be sent with the message.
Return type:

Message

Returns:

The new Message created.

user
Return type:Optional[User]
Returns:If this channel is a private channel, the User of the other user.
voice_members
Return type:List[Member]
Returns:A list of members that are in this voice channel.
webhooks
Return type:AsyncIterator[Webhook]
Returns:A AsyncIteratorWrapper for the Webhook 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 of Message 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:
  • limit (int) – The maximum number of messages to get.
  • before (Optional[int]) – The snowflake ID to get messages before.
  • after (Optional[int]) – The snowflake ID to get messages after.
Return type:

HistoryIterator

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!) if fallback_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.

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:
  • content (Optional[str]) – The content of the message to send.
  • tts (bool) – Should this message be text to speech?
  • embed (Optional[Embed]) – An embed object to send with this message.
Return type:

Message

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.

  • 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:

Message

Returns:

The new Message created.

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:
  • channel (Channel) – The Channel to iterate over.
  • max_messages (int) – The maximum number of messages to return. <= 0 means infinite.
  • before (Optional[int]) – The message ID to fetch before.
  • after (Optional[int]) – The message ID to fetch after.

Changed in version 0.7.0: Removed the client parameter.

await all()[source]

Gets a flattened list of items from the history.

Return type:List[Message]
await fill_messages()[source]

Called to fill the next <n> messages.

This is called automatically by __anext__(), but can be used to fill the messages anyway.

Return type:None
await next()[source]

Gets the next item in history.

Return type:Message