Skip to content

Automatic hot-reloading for your discord.py command files.

License

Notifications You must be signed in to change notification settings

soosBot-com/cogwatch

 
 

Repository files navigation

FORKED FROM /robertwayne/cogwatch

Cog Watch

With the recent news that `discord.py` will no longer be mainainted, as well as my own bot being moved over to Rust w/ Twilight for several months now, this project will no longer be maintained.


Automatic hot-reloading for your discord.py command files.

Version Python Version

cogwatch is a utility that you can plug into your discord.py bot that will watch your command files directory (cogs) and automatically reload them as you modify or move them around in real-time. No more reloading your bot / command yourself every time you edit an embed just to make sure it looks perfect!

Features

  • Automatically reloads commands in real-time as you edit them (no !reload needed).
  • Can handle the loading of all your commands on start-up (no boilerplate).

Getting Started

You can install the library with pip install cogwatch.

Import the watch decorator and apply it to your on_ready method and let the magic take effect.

See the examples directory for more details, as well as an example on how to use the cog concept in dpymenus if you are unfamiliar with it.

import asyncio
from discord.ext import commands
from cogwatch import watch


class ExampleBot(commands.Bot):
    def __init__(self):
        super().__init__(command_prefix='!')

    @watch(path='commands')
    async def on_ready(self):
        print('Bot ready.')

    async def on_message(self, message):
        if message.author.bot:
            return

        await self.process_commands(message)


async def main():
    client = ExampleBot()
    await client.start('YOUR_TOKEN_GOES_HERE')

if __name__ == '__main__':
    asyncio.run(main())

Configuration

You can pass any of these values to the decorator:

path='commands': Root name of the cogs directory; cogwatch will only watch within this directory -- recursively.

debug=True: Whether to run the bot only when the Python __debug__ flag is True. Defaults to True.

loop=None: Custom event loop. Defaults to the current running event loop.

default_logger=True: Whether to use the default logger (to sys.stdout) or not. Defaults to True.

preload=False: Whether to detect and load all found cogs on start. Defaults to False.

NOTE: cogwatch will only run if the __debug__ flag is set on Python. You can read more about that here. In short, unless you run Python with the -O flag from your command line, __debug__ will be True. If you just want to bypass this feature, pass in debug=False and it won't matter if the flag is enabled or not.

Logging

By default, the utility has a logger configured so users can get output to the console. You can disable this by passing in default_logger=False. If you want to hook into the logger -- for example, to pipe your output to another terminal or tail a file -- you can set up a custom logger like so:

import logging
import sys

watch_log = logging.getLogger('cogwatch')
watch_log.setLevel(logging.INFO)
watch_handler = logging.StreamHandler(sys.stdout)
watch_handler.setFormatter(logging.Formatter('[%(name)s] %(message)s'))
watch_log.addHandler(watch_handler)

Check out my other discord.py utility: dpymenus -- Simplified menus for discord.py developers.

About

Automatic hot-reloading for your discord.py command files.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • Python 100.0%