diff --git a/.env.example b/.env.example index 8e48bea..d4143bf 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,7 @@ DISCORD_TOKEN=your_discord_bot_token_here CHANNEL_ID=your_channel_id_here,optional_second_channel_id STARTUP_ANNOUNCEMENT= +STARTUP_ANNOUNCEMENT_CHANNEL_ID= # Bot Configuration COMMAND_PREFIX=! diff --git a/README.md b/README.md index 4d0ab81..73f1b69 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,7 @@ Environment variables in `.env`: | `DISCORD_TOKEN` | Your Discord bot token | Required | | `CHANNEL_ID` | Discord channel ID(s) for updates (comma-separated for multiple) | Required | | `STARTUP_ANNOUNCEMENT` | Optional message to send when bot starts (empty = no announcement) | `""` | +| `STARTUP_ANNOUNCEMENT_CHANNEL_ID` | Channel ID for startup announcements (defaults to first CHANNEL_ID) | `""` | | `COMMAND_PREFIX` | Command prefix for bot | `!` | | `PRIMARY_TICKER` | Stock ticker for hourly updates | `PYPL` | | `UPDATE_INTERVAL_HOURS` | Hours between updates | `1` | @@ -173,7 +174,9 @@ CHANNEL_ID=1442203998932304035,9876543210123456789 **Startup Announcements:** Send a one-time message when the bot starts (useful for announcing updates): ``` STARTUP_ANNOUNCEMENT=Bot updated with new features: colored price changes and FinViz charts! +STARTUP_ANNOUNCEMENT_CHANNEL_ID=1234567890123456789 ``` +If `STARTUP_ANNOUNCEMENT_CHANNEL_ID` is not set, announcements are sent to the first channel in `CHANNEL_ID`. ## Switching Stock API Providers diff --git a/bot.py b/bot.py index 3854c00..51847a1 100644 --- a/bot.py +++ b/bot.py @@ -104,7 +104,7 @@ class StockBot(commands.Bot): await self.send_stock_update(self.primary_ticker, channel_id) async def send_startup_announcement(self): - """Send startup announcement to configured channels.""" + """Send startup announcement to configured announcement channel.""" embed = discord.Embed( title="🤖 Bot Update", description=Config.STARTUP_ANNOUNCEMENT, @@ -112,13 +112,27 @@ class StockBot(commands.Bot): timestamp=datetime.now(pytz.timezone('America/New_York')) ) - for channel_id in self.target_channel_ids: - channel = self.get_channel(channel_id) - if channel: - await channel.send(embed=embed) - logger.info(f"Sent startup announcement to channel {channel_id}") - else: - logger.error(f"Could not send announcement to channel {channel_id}") + # Use dedicated announcement channel if configured, otherwise use first target channel + announcement_channel_id = Config.STARTUP_ANNOUNCEMENT_CHANNEL_ID + if announcement_channel_id: + try: + channel_id = int(announcement_channel_id) + except ValueError: + logger.error(f"Invalid STARTUP_ANNOUNCEMENT_CHANNEL_ID: {announcement_channel_id}") + return + else: + channel_id = self.target_channel_ids[0] if self.target_channel_ids else None + + if not channel_id: + logger.error("No channel configured for startup announcement") + return + + channel = self.get_channel(channel_id) + if channel: + await channel.send(embed=embed) + logger.info(f"Sent startup announcement to channel {channel_id}") + else: + logger.error(f"Could not find announcement channel {channel_id}") async def send_stock_update(self, ticker: str, channel_id: int): """ diff --git a/config.py b/config.py index 37e7400..f9107f8 100644 --- a/config.py +++ b/config.py @@ -13,6 +13,7 @@ class Config: CHANNEL_IDS = [id.strip() for id in os.getenv('CHANNEL_ID', '').split(',') if id.strip()] COMMAND_PREFIX = os.getenv('COMMAND_PREFIX', '!') STARTUP_ANNOUNCEMENT = os.getenv('STARTUP_ANNOUNCEMENT', '') + STARTUP_ANNOUNCEMENT_CHANNEL_ID = os.getenv('STARTUP_ANNOUNCEMENT_CHANNEL_ID', '') # Stock configuration PRIMARY_TICKER = os.getenv('PRIMARY_TICKER', 'PYPL')