Skip to main content

A discord.py extension for automatic edit tracking

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.3.tar.gz (7.3 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.3-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: discord_ext_track_edits-0.1.3.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for discord_ext_track_edits-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8b7c2b45170bb1b419cffdf4b2aa74f327b94a56571f069b80060de1032875f3
MD5 e9d51b80b52d597b0b385095a3fcf2d0
BLAKE2b-256 59066d9d028b0fed293263619ddb279036fa8b9337cc6dd43510aa22f72dc511

See more details on using hashes here.

File details

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

File metadata

  • Download URL: discord_ext_track_edits-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for discord_ext_track_edits-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7e265eb0d29552278eef87bd40baf4b3fc8a4b718a2555de85773119f08d557e
MD5 28af8cca6bc182018a4f6ecd9753010e
BLAKE2b-256 e79d5a43129b9c99944af554d900c3933b1cfbc67e509684b73701dc0d8d0b89

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