Skip to main content

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

Project description

Cog Watch

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

Version Python Version

Getting Started

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 manually reloading commands with other commands, or (worse yet) restarting your bot, every time you edit that embed!

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.

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


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

    @watch(cogs_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())

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. This is a development tool. You should not run it on production.

Using a Classless Bot

If you are using a classless bot you cannot use the decorator method and instead must manually create your watcher.

from discord.ext import commands
from cogwatch import Watcher

client = commands.Bot(command_prefix='!')


@client.event
async def on_ready():
    print('Bot ready.')

    watcher = Watcher(client, cogs_path='commands')
    await watcher.start()

client.run('YOUR_TOKEN_GOES_HERE')

Configuration

You can pass any of these values to the decorator:

cogs_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 startup. Defaults to False.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cogwatch-1.1.7.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

cogwatch-1.1.7-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file cogwatch-1.1.7.tar.gz.

File metadata

  • Download URL: cogwatch-1.1.7.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.0 Windows/10

File hashes

Hashes for cogwatch-1.1.7.tar.gz
Algorithm Hash digest
SHA256 022818fc80f906c9e0bc43260158318de2174d6bbaab87991396b30e9a1fbd3d
MD5 d3249a4f0538be7454b8e783a7e76965
BLAKE2b-256 f010f2b29d8ca6f1d2a9a80e51a6497d1685e493e87fef49869df92c58808c2b

See more details on using hashes here.

Provenance

File details

Details for the file cogwatch-1.1.7-py3-none-any.whl.

File metadata

  • Download URL: cogwatch-1.1.7-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.0 Windows/10

File hashes

Hashes for cogwatch-1.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d941aa8e06c5cc95f9a7f9b328e528b5f369aa34cff6108a305a04920780fcdd
MD5 ecc31b3f04810dd8bc2bc3ab00bd1bc3
BLAKE2b-256 6b913de1d7f04be86dd99085cde17af314b1e99f33187539882bb3d4fa193f72

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page