qq-botpy is the official Python SDK for creating bots on Tencent's QQ Channels, providing an easy-to-use and efficient framework for developers. It abstracts the complexities of the QQ Open Platform API, enabling quick development of features like message handling and event listening. The library is actively maintained, with frequent updates; the current stable version is 1.2.1.
pip install qq-botpyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a basic QQ Channel bot that responds to @-mentions. It requires your QQ bot's AppID and AppSecret, which should be set as environment variables `QQ_BOT_APP_ID` and `QQ_BOT_APP_SECRET` for security, or replaced directly with your credentials. The bot will print a 'ready' message and reply to any public guild message where it is @-mentioned.
Update your bot configuration to use `client.run(appid='YOUR_APP_ID', secret='YOUR_APP_SECRET')` instead of `client.run(token='YOUR_TOKEN')`. Obtain your AppSecret from the QQ bot development settings page.
Always use `pip install qq-botpy` to install the correct library. After installation, the package is imported as `import botpy`.
Ensure your development and deployment environment uses Python 3.7 or a newer version.
Before processing `message.content`, use `message.content.replace(f"<@{self.robot.id}>", "").strip()` to remove the bot's mention and leading/trailing whitespace.Implement rate limiting or a cooldown mechanism in your bot logic, especially for high-frequency interactions or large groups. Consider truncating long replies if they might hit character limits.
Navigate to your bot's settings in the QQ Open Platform and enable the 'group chat' scenario. This usually requires a review period.
Run `pip uninstall botpy` if you installed the incorrect package, then run `pip install qq-botpy`.
Double-check your `APP_ID` and `APP_SECRET` from the QQ Open Platform. Ensure they are correctly passed to `client.run()`. Verify that your server's IP address is whitelisted in the QQ Open Platform settings if applicable.
Review the content you are attempting to send. Ensure it adheres to QQ API message format requirements. If sending rich media, ensure the payload is correct. Check for rate limits, as frequent requests can sometimes lead to such errors.
This can indicate network issues or a transient API problem with the QQ backend. Check your network connection and ensure your bot's server can reach the QQ API. Consider adding retry logic or increasing the client's timeout setting if available.