diff --git a/ovos_PHAL_plugin_discord_bot/__init__.py b/ovos_PHAL_plugin_discord_bot/__init__.py index 0e0deac..ac55782 100644 --- a/ovos_PHAL_plugin_discord_bot/__init__.py +++ b/ovos_PHAL_plugin_discord_bot/__init__.py @@ -12,8 +12,8 @@ from ovos_utils.log import LOG from ovos_utils import classproperty from ovos_utils.process_utils import RuntimeRequirements from json_database import JsonConfigXDG - - + + class DiscordBotPlugin(PHALPlugin): def __init__(self, bus=None, config=None): super().__init__(bus, "ovos-PHAL-plugin-discord-bot", config) @@ -28,6 +28,17 @@ class DiscordBotPlugin(PHALPlugin): self.bus.on("configuration.updated", self.init_configuration) reinstall_hint = "pip install --upgrade --no-deps --force-reinstall git+https://git.sebastianmaki.fi/sebastian/ovos-PHAL-plugin-discord-bot.git" LOG.info(f"Reinstall hint: {reinstall_hint}") + # Discord event: bot is ready + @self.bot.event + async def on_ready(): + myLoop.start() + print(f'{bot.user} has connected to Discord!') + + admin = await get_discord_user_by_id(DISCORD_ADMIN_ID) + if admin: + print(f"Admin is {admin.name}") + await admin.send("I'm now online") + self.setup_configuration() @classproperty @@ -94,5 +105,9 @@ class DiscordBotPlugin(PHALPlugin): # Start the Discord bot LOG.info("Starting the bot") self.bot.run(self.api_token) + + # Helper function to get Discord user by ID + async def get_discord_user_by_id(user_id) -> discord.User: + return await self.bot.fetch_user(user_id)