Allow pins to use replies instead of arguments

This commit is contained in:
Stijn De Clercq 2022-01-05 19:36:47 +01:00
parent e130bf4a25
commit ea18dea411

View file

@ -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.")