Skip to main content

A discord.py extension for automatic edit tracking

Reason this release was yanked:

caused memory leak due to improper cache purging

Project description

discord-ext-track-edits

A discord.py extension that implements edit tracking for prefix commands, inspired by poise:

  • When user edits their message, automatically update bot response
  • When user deletes their message, automatically delete corresponding bot response, if it exists.

Usage

The extension contains an EditTrackerCog and an EditTrackableContext. They must be used together for edit tracking to work.

Responses will be tracked only when you explicitly .reply() to the invocation message.

from datetime import timedelta
from typing import Type, Union
from typing_extensions import override

import discord
from discord.ext import commands
from discord.ext.track_edits import EditTrackerCog, EditTrackableContext

class Bot(commands.Bot):
    async def setup_hook(self) -> None:
        await self.add_cog(
            EditTrackerCog(
                self,
                max_duration=timedelta(minutes=5),
                execute_untracked_edits=True,
                ignore_edits_if_not_yet_responded=False,
            ),
        )

    @override
    async def get_context(
        self,
        origin: Union[discord.Message, discord.Interaction],
        *,
        cls: Type[EditTrackableContext] = EditTrackableContext,
    ) -> EditTrackableContext:
        return await super().get_context(origin, cls=cls)

# your usual bot setup code here

Cog options

  • max_duration: How long to track bot responses for. If set to None, bot responses will be tracked indefinitely until the process is shut down. (default: 5 minutes)
  • execute_untracked_edits: Whether to execute a command that was previously untracked, for example, when the user makes a typo and edits it into a valid invocation. (default: True)
  • ignore_edits_if_not_yet_responded: Whether to ignore edits on messages that have not been responded to. This happens if the edits happens before the command has sent a response, or if the command does not respond at all. (default: False)

Command options

Command options are supplied through the extras dictionary:

@commands.command(extras={"invoke_on_edit": False})
async def cmd(ctx):
    ...
  • invoke_on_edit: Whether to rerun the command if an existing invocation message is edited (default: True)
  • track_deletion: Whether to delete the bot response if an existing invocation message is deleted (default: True)
  • reuse_response: Whether to post subsequent responses as edits to the original response (default: True)

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

discord_ext_track_edits-0.1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

discord_ext_track_edits-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file discord_ext_track_edits-0.1.0.tar.gz.

File metadata

File hashes

Hashes for discord_ext_track_edits-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c3513a1070f62d2b62a468d9158ff88e4197aac30b9633cb63a2a2b8cfb3ef49
MD5 c383a97e578cfc0d9b2a61cb582fee6d
BLAKE2b-256 619c3ac10b214e48627afd76c4020ca698c6d97a0de3d3fb7c32d3661823ad56

See more details on using hashes here.

File details

Details for the file discord_ext_track_edits-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for discord_ext_track_edits-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d27b32770273ddebf252d0c7f57f35ce4c93a056e55efcba4bcbcea7b0491de6
MD5 4f5fd8ea4150e39fe2673c3cc0334290
BLAKE2b-256 ff13a346153a4292715a3b1892042dd175d52857b14c589c40483796fbbe3304

See more details on using hashes here.

Supported by

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