diff --git a/chat_listener.py b/chat_listener.py index 00dd6c6..2246352 100644 --- a/chat_listener.py +++ b/chat_listener.py @@ -1,23 +1,33 @@ from twitchio.ext import commands +class NullAdapter: + """A dummy web adapter that does nothing to prevent twitchio from starting a webserver.""" + async def start(self): + pass + + async def stop(self): + pass + class TwitchBot(commands.Bot): def __init__(self, access_token: str, client_id: str, client_secret: str, bot_id: str, channel_name: str, websocket_manager, db_user_id: int): self.websocket_manager = websocket_manager # Store our application's database user ID to avoid conflict with twitchio's internal 'owner_id' self.db_user_id = db_user_id + # Force the bot to use our dummy adapter that does nothing. + # This is the definitive fix to prevent any port conflicts. + adapter = NullAdapter() + super().__init__( token=access_token, + web_server_adapter=adapter, prefix='!', # A prefix is required but won't be used for reading chat initial_channels=[channel_name], # These are now required by twitchio client_id=client_id, client_secret=client_secret, # The 'bot_id' is the Twitch ID of the user account the bot is running as - bot_id=bot_id, id=bot_id, - # Force the internal webserver to a harmless, high port to permanently - # resolve the "address already in use" error during hot-reloads. - web_server_adapter_kwargs={'host': 'localhost', 'port': 8123} + bot_id=bot_id, id=bot_id ) self.channel_name = channel_name