This commit refactors the `disagreement/__init__.py` file to import and export new models, enums, and components. The primary changes are: - Add imports and exports for `Member`, `Role`, `Attachment`, `Channel`, `ActionRow`, `Button`, `SelectOption`, `SelectMenu`, `Embed`, `PartialEmoji`, `Section`, `TextDisplay`, `Thumbnail`, `UnfurledMediaItem`, `MediaGallery`, `MediaGalleryItem`, `Container`, and `Guild` from `disagreement.models`. - Add imports and exports for `ButtonStyle`, `ChannelType`, `MessageFlags`, `InteractionType`, `InteractionCallbackType`, and `ComponentType` from `disagreement.enums`. - Add `Interaction` from `disagreement.interactions`. - Add `ui` and `ext` as top-level modules. - Update `disagreement.ext/__init__.py` to expose `app_commands`, `commands`, and `tasks`. These changes consolidate the library's public API, making new features more accessible. The example files were also updated to use the direct imports from the `disagreement` package or its `ext` subpackage, improving readability and consistency.
38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
"""Example showing how to read a channel's message history."""
|
|
|
|
import asyncio
|
|
import os
|
|
import sys
|
|
|
|
# Allow running example from repository root
|
|
if os.path.join(os.getcwd(), "examples") == os.path.dirname(os.path.abspath(__file__)):
|
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
|
|
|
from disagreement import Client, Channel
|
|
from disagreement.models import TextChannel
|
|
|
|
try:
|
|
from dotenv import load_dotenv
|
|
except ImportError: # pragma: no cover - example helper
|
|
load_dotenv = None
|
|
print("python-dotenv is not installed. Environment variables will not be loaded")
|
|
|
|
if load_dotenv:
|
|
load_dotenv()
|
|
|
|
BOT_TOKEN = os.environ.get("DISCORD_BOT_TOKEN", "")
|
|
CHANNEL_ID = os.environ.get("DISCORD_CHANNEL_ID", "")
|
|
|
|
client = Client(token=BOT_TOKEN)
|
|
|
|
|
|
async def main() -> None:
|
|
channel = await client.fetch_channel(CHANNEL_ID)
|
|
if isinstance(channel, TextChannel):
|
|
async for message in channel.history(limit=10):
|
|
print(message.content)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|