Skip to content

Commit

Permalink
feat: pin context message command
Browse files Browse the repository at this point in the history
Allow anyone to pin / unpin messages using Context Message Commands
  • Loading branch information
AiroPi committed Nov 12, 2024
1 parent b2d50ca commit 43667a7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ loaded_extensions = [
"colloscope_helper",
"birthday",
"admin",
"pin",
]
35 changes: 35 additions & 0 deletions src/cogs/pin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from discord import Message, app_commands
from discord.ext.commands import Cog # pyright: ignore[reportMissingTypeStubs]

if TYPE_CHECKING:
from discord import Interaction

from bot import FISABot


class Pin(Cog):
def __init__(self, bot: FISABot) -> None:
self.bot = bot

self.bot.tree.add_command(
app_commands.ContextMenu(
name="Epingler/Desepingler",
callback=self.pin,
)
)

async def pin(self, interaction: Interaction, message: Message):
if message.pinned:
await message.unpin()
await interaction.response.send_message(f"Message {message.jump_url} désépinglé.", ephemeral=True)
else:
await message.pin()
await interaction.response.send_message(f"Message {message.jump_url} épinglé.", ephemeral=True)


async def setup(bot: FISABot) -> None:
await bot.add_cog(Pin(bot))

0 comments on commit 43667a7

Please sign in to comment.