This commit is contained in:
4 files changed
+47
-1
No files matched your search
@@ -1,4 +1,7 @@
|
||||
from discord import ApplicationContext, Cog, slash_command, InteractionContextType
|
||||
from typing import Callable, List
|
||||
|
||||
from discord import ApplicationContext, Cog, slash_command, InteractionContextType, option, User, default_permissions, \
|
||||
Forbidden, Message
|
||||
from libbot.i18n import _, in_every_locale
|
||||
|
||||
from javelina.classes.pycord_bot import PycordBot
|
||||
@@ -50,6 +53,40 @@ class CogAdmin(Cog):
|
||||
ephemeral=True,
|
||||
)
|
||||
|
||||
# TODO Implement i18n
|
||||
# TODO Account for rate limits
|
||||
@slash_command(
|
||||
name="clear",
|
||||
description=_("description", "commands", "clear"),
|
||||
description_localizations=in_every_locale("description", "commands", "clear"),
|
||||
contexts={InteractionContextType.guild},
|
||||
)
|
||||
@option("amount", description="How many messages to delete", min_value=1, max_value=100)
|
||||
@option("user", description="User whose balance to check (if not your own)", required=False)
|
||||
@default_permissions(manage_messages=True)
|
||||
async def command_clear(self, ctx: ApplicationContext, amount: int, user: User = None) -> None:
|
||||
try:
|
||||
check: Callable[[Message], bool] = (lambda msg: True) if user is None else (lambda msg: msg.author.id == user.id)
|
||||
|
||||
purged_messages: List[Message] = await ctx.channel.purge(limit=amount, check=check)
|
||||
|
||||
await ctx.respond(
|
||||
embed=self.bot.create_embed(description=f"Deleted {len(purged_messages)} message(s)."),
|
||||
ephemeral=True,
|
||||
delete_after=3.0,
|
||||
)
|
||||
except Forbidden:
|
||||
await ctx.respond(
|
||||
embed=self.bot.create_embed_error("Missing permissions", description="The bot does not have permission to delete messages. Please, allow the bot to delete messages and try again."),
|
||||
ephemeral=True,
|
||||
)
|
||||
except Exception as exc:
|
||||
await ctx.respond(
|
||||
embed=self.bot.create_embed_error("Something went wrong", description=f"Could not delete messages:\n```\n{exc}\n```"),
|
||||
ephemeral=True,
|
||||
)
|
||||
|
||||
|
||||
|
||||
def setup(bot: PycordBot) -> None:
|
||||
bot.add_cog(CogAdmin(bot))
|
||||
@@ -63,6 +63,9 @@
|
||||
"commands": {
|
||||
"reload": {
|
||||
"description": "Reload bot's configuration"
|
||||
},
|
||||
"clear": {
|
||||
"description": "Delete some messages in the current channel"
|
||||
}
|
||||
},
|
||||
"actions": {
|
||||
|
||||
@@ -63,6 +63,9 @@
|
||||
"commands": {
|
||||
"reload": {
|
||||
"description": "Reload bot's configuration"
|
||||
},
|
||||
"clear": {
|
||||
"description": "Delete some messages in the current channel"
|
||||
}
|
||||
},
|
||||
"actions": {
|
||||
|
||||
@@ -77,6 +77,9 @@
|
||||
"commands": {
|
||||
"reload": {
|
||||
"description": "Перезавантажити конфігурацію бота"
|
||||
},
|
||||
"clear": {
|
||||
"description": "Delete some messages in the current channel"
|
||||
}
|
||||
},
|
||||
"actions": {
|
||||
|
||||
Reference in new issue
Block a user