From ea18dea41167d5174da6ebeb813cc8fe8c14b268 Mon Sep 17 00:00:00 2001 From: Stijn De Clercq Date: Wed, 5 Jan 2022 19:36:47 +0100 Subject: [PATCH] Allow pins to use replies instead of arguments --- cogs/school.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cogs/school.py b/cogs/school.py index 4eefb70..cc6e43f 100644 --- a/cogs/school.py +++ b/cogs/school.py @@ -58,13 +58,27 @@ class School(commands.Cog): @commands.command(name="Pin", usage="[Message]") @help.Category(category=Category.Other) - async def pin(self, ctx, message: discord.Message): + async def pin(self, ctx, message: discord.Message = None): # In case people abuse, check if they're blacklisted blacklist = [] if ctx.author.id in blacklist: return + # Support replying to the message that should be pinned + if message is None: + reference = ctx.message.reference + + if reference is None: + return await ctx.reply("Controleer je argumenten.") + + # If the message is cached, avoid sending an API call + if not reference.cached_message: + # Message is always in the current channel because we came from a reply + message = await ctx.channel.fetch_message(reference.message_id) + else: + message = reference.cached_message + if message.is_system(): return await ctx.send("Dus jij wil system messages pinnen?\nMag niet.")