Skip to main content

Revolt.py

An async library to interact with the https://revolt.chat API.

You can join the support server here and find the library's documentation here.

Installing

You can use pip to install revolt.py. It differs slightly depending on what OS/Distro you use.

On Windows

py -m pip install -U revolt-baidu.py # -U to update

On macOS and Linux

python3 -m pip install -U revolt-baidu.py

Example

More examples can be found in the examples folder.

import revolt
import asyncio

class Client(revolt.Client):
    async def on_message(self, message: revolt.Message):
        if message.content == "hello":
            await message.channel.send("hi how are you")

async def main():
    async with revolt.utils.client_session() as session:
        client = Client(session, "BOT TOKEN HERE")
        await client.start()

asyncio.run(main())

Bot interaction example

class Client(revolt.Client):
    async def on_interaction(
        self, interaction: InteractionEventPayload, message: revolt.Message
    ) -> None:
        logger.info("interaction %s", interaction)
        user = self.get_user(interaction["author_id"])
        await message.channel.send(
            f"Username: {user.name} Your choice is: {interaction['content']} "
        )
        components = message.components
        for com in components:
            if isinstance(com, ButtonComponent):
                com.label = "edited"
                com.enabled = False
            elif isinstance(com, StatusComponent):
                com.label = "new status"

        # update the button component's label
        await message.edit(content="edited", components=components)

    async def on_message(self, message: revolt.Message):
        if message.content == "/button":
            await message.channel.send(
                "you have these options",
                components=[
                    ButtonComponent(
                        style="color:white; backgroundColor:green; fontSize:16px; fontWeight:400;",
                        label="continue",
                        enabled=True,
                    ),
                    LineBreakComponent(),
                    StatusComponent(label="this is status window"),
                ],
            )

Stream Message Example

from revolt.stream_handler import StreamGenerator

class Client(revolt.Client):
    def need_reply(self, message: revolt.Message) -> bool:
        message_user = self.get_user(message.author.id)
        is_response = False
        for user in message.mentions:
            if user.id == self.user.id:
                is_response = True

        if message.channel.channel_type == ChannelType.direct_message:
            is_response = True

        return message_user.id != self.user.id and is_response

    async def on_message(self, message: revolt.Message):
        if not self.need_reply(message):
            return

        g = StreamGenerator()

        async def stream_message():
            for i in range(10):
                await g.push_message(f"hello {i}  ")

            # needs to call g.close when generating has been finished
            await g.close()

        asyncio.create_task(stream_message())
        await message.channel.send(stream_generator=g.generator())

Metadata

Release files for revolt-baidu.py 0.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for revolt-baidu.py 0.0.11
File Size Uploaded Provenance Actions
revolt_baidu.py-0.0.11.tar.gz 50.2 kB Without provenance Details for revolt_baidu.py-0.0.11.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for revolt-baidu.py 0.0.11
File Interpreter ABI Platform Actions
revolt_baidu.py-0.0.11-py3-none-any.whl Python 3 none any Details for revolt_baidu.py-0.0.11-py3-none-any.whl

Total release size: 121.7 kB

Release files / revolt_baidu.py-0.0.11.tar.gz

Download URL revolt_baidu.py-0.0.11.tar.gz
Size 50.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7a2e9a2353485f078afec8fca80fb310cf4f34d2d088f9e4315b9bed02170194
BLAKE2b-256 checksum
How to use checksums
538fd4448e825a9b762415b524df8a1bd8e40bc851668259763b7ce8c452ae55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.3

Release files / revolt_baidu.py-0.0.11-py3-none-any.whl

Download URL revolt_baidu.py-0.0.11-py3-none-any.whl
Size 71.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aece006cbcc2b21ec95b98e990d9fec9a988c0c04118dd8bea5e44f98d1c9661
BLAKE2b-256 checksum
How to use checksums
3b038515c07bce8e3e90fb4d732485a572c75cdefc7e02b4bf255fe580ed7111
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.23.3

Security for revolt-baidu.py 0.0.11

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page