-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow anyone to pin / unpin messages using Context Message Commands
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ loaded_extensions = [ | |
"colloscope_helper", | ||
"birthday", | ||
"admin", | ||
"pin", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |