bulk delete messages

This commit is contained in:
ddorn 2020-05-05 13:39:44 +02:00
parent cec426cd8d
commit 7e50c11d66
2 changed files with 23 additions and 5 deletions

View File

@ -2,8 +2,15 @@ import asyncio
from pprint import pprint
import discord
from discord import TextChannel, PermissionOverwrite
from discord.ext.commands import command, has_role, Bot, Cog, ExtensionNotLoaded
from discord import TextChannel, PermissionOverwrite, Message
from discord.ext.commands import (
command,
has_role,
Bot,
Cog,
ExtensionNotLoaded,
Context,
)
from discord.utils import get
from ptpython.repl import embed
@ -182,6 +189,19 @@ class DevCog(Cog, name="Dev tools"):
await ctx.message.delete()
await ctx.send(" ".join(msg))
@command(name="del")
@has_role(Role.CNO)
async def del_range_cmd(self, ctx: Context, id1: Message, id2: Message):
"""
(cno) Supprime les messages entre les deux IDs en argument.
"""
channel: TextChannel = id1.channel
to_delete = [
message async for message in channel.history(before=id1, after=id2)
] + [id1, id2]
await channel.delete_messages(to_delete)
await ctx.message.delete()
def setup(bot: CustomBot):
bot.add_cog(DevCog(bot))

View File

@ -1,12 +1,10 @@
#!/bin/python
from src.constants import *
from src.core import CustomBot
# We allow "! " to catch people that put a space in their commands.
# It must be in first otherwise "!" always match first and the space is not recognised
from src.core import CustomBot
bot = CustomBot(("! ", "!"))
# Global variable to hold the tirages.