# Distillery Bot The Distillery Bot is the main Discord bot component of the Distillery system. It is responsible for interacting with users, listening for slash commands, validating requests, managing subscriptions and credits, and sending generated images back to the users. ### Overview The Distillery Bot acts as the primary interface between Discord users and the Distillery system. It handles user commands, manages user data, and coordinates with other components to ensure a smooth user experience. ### Distillery Bot Initialization The Distillery Bot is initialized by loading the necessary configuration files (see [[Bot-Specific Configuration]]) and setting up the Discord bot using the [[discord.py library]]. This includes defining intents, registering event listeners, and creating the `DistilleryCog` class. [[What Does Initialization Mean]] Let's take a closer look how it's done in code: [[Distillery Bot Initialization]] ### Slash Commands and DistilleryCog The bot utilizes [[Discord's slash commands]] feature for user interaction. The `DistilleryCog` class handles the creation and registration of slash commands based on the configuration defined in `DISTILLERY_COMMANDS`. Command handling logic is implemented in the `distillery_commands.py` file [[Distillery Commands]]. [[DistilleryCog]] detailed documentation ### Image Sending Routine [[Distillery Bot Send Routine]] When images are ready in the `SendQueue`, the bot retrieves them, downloads the image files from S3 using the `distillery_aws.py` module [[distillery_aws]], and sends them back to the respective users on Discord. The `send_routine` function is an asynchronous function responsible for sending generated images to the appropriate Discord channels or users. It processes a tuple containing request details and handles the sending of images based on those details. Let's take a closer look at it [[Distillery Bot Send Routine]] ### Check Queue and Send Task The [[check_queue_and_send]] function is an asynchronous task that periodically checks the [[SendQueue]] and processes any pending requests. ### Utilities and Helpers The Distillery bot utilizes various utility functions and helper classes to perform specific tasks and support the main functionality of the bot. These utilities and helpers provide reusable and modular code for common operations. See further details - [[Cooldown]] The Cooldown class is a helper class used for rate limiting the number of Discord requests per second. It ensures that the bot does not exceed the rate limits imposed by the Discord API. - [[Flatten List]] The `flatten_list` function is a utility function that flattens a nested list into a single-level list. It recursively traverses the nested list and appends all elements to a new flat list. - [[Reset Request Counter]] The `reset_request_counter` function is an asynchronous utility function that resets a specific request counter using the `AWSManager` class. - [[Refill Subscription Distill Credits]] The `refill_subscription_distill_credits` function is an asynchronous utility function that refills the subscription distill credits for users.