# Buggy code
async def after(
    self, ctx: commands.Context, message_id: int, delete_pinned: bool = False
):
    """Delete all messages after a specified message.

    To get a message id, enable developer mode in Discord's
    settings, 'appearance' tab. Then right click a message
    and copy its id.
    """

    channel = ctx.channel
    author = ctx.author

    try:
        after = await channel.get_message(message_id)
    except discord.NotFound:
        return await ctx.send(_("Message not found."))

    to_delete = await self.get_messages_for_deletion(
        channel=channel, number=None, after=after, delete_pinned=delete_pinned
    )
    to_delete.append(ctx.message)

    reason = "{}({}) deleted {} messages in channel {}.".format(
        author.name, author.id, len(to_delete), channel.name
    )
    log.info(reason)

    await mass_purge(to_delete, channel)


# Traceback (discord.ext.commands.errors.CommandInvokeError)
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/discord/ext/commands/core.py", line 61, in wrapped
ret = await coro(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/redbot/cogs/cleanup/cleanup.py", line 240, in after
await mass_purge(to_delete, channel)
File "/usr/local/lib/python3.7/dist-packages/redbot/core/utils/mod.py", line 42, in mass_purge
await channel.delete_messages(messages[:100])
File "/usr/local/lib/python3.7/dist-packages/discord/channel.py", line 222, in delete_messages
await self._state.http.delete_messages(self.id, message_ids)
File "/usr/local/lib/python3.7/dist-packages/discord/http.py", line 213, in request
raise HTTPException(r, data)
discord.errors.HTTPException: BAD REQUEST (status code: 400): Invalid Form Body
In messages.6: The set already contains this value

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/discord/ext/commands/bot.py", line 898, in invoke
await ctx.command.invoke(ctx)
File "/usr/local/lib/python3.7/dist-packages/redbot/core/commands/commands.py", line 409, in invoke
await super().invoke(ctx)
File "/usr/local/lib/python3.7/dist-packages/discord/ext/commands/core.py", line 1024, in invoke
await ctx.invoked_subcommand.invoke(ctx)
File "/usr/local/lib/python3.7/dist-packages/discord/ext/commands/core.py", line 614, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/usr/local/lib/python3.7/dist-packages/discord/ext/commands/core.py", line 70, in wrapped
raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: BAD REQUEST (status code: 400): Invalid Form Body
In messages.6: The set already contains this value

# Fixed code
async def after(
    self, ctx: commands.Context, message_id: int, delete_pinned: bool = False
):
    """Delete all messages after a specified message.

    To get a message id, enable developer mode in Discord's
    settings, 'appearance' tab. Then right click a message
    and copy its id.
    """

    channel = ctx.channel
    author = ctx.author

    try:
        after = await channel.get_message(message_id)
    except discord.NotFound:
        return await ctx.send(_("Message not found."))

    to_delete = await self.get_messages_for_deletion(
        channel=channel, number=None, after=after, delete_pinned=delete_pinned
    )

    reason = "{}({}) deleted {} messages in channel {}.".format(
        author.name, author.id, len(to_delete), channel.name
    )
    log.info(reason)

    await mass_purge(to_delete, channel)