|
17 | 17 |
|
18 | 18 |
|
19 | 19 | class General(commands.Cog, name="general"):
|
20 |
| - def __init__(self, bot): |
| 20 | + def __init__(self, bot) -> None: |
21 | 21 | self.bot = bot
|
| 22 | + self.context_menu_user = app_commands.ContextMenu( |
| 23 | + name="Grab ID", callback=self.grab_id |
| 24 | + ) |
| 25 | + self.bot.tree.add_command(self.context_menu_user) |
| 26 | + self.context_menu_message = app_commands.ContextMenu( |
| 27 | + name="Remove spoilers", callback=self.remove_spoilers |
| 28 | + ) |
| 29 | + self.bot.tree.add_command(self.context_menu_message) |
| 30 | + |
| 31 | + # Message context menu command |
| 32 | + async def remove_spoilers( |
| 33 | + self, interaction: discord.Interaction, message: discord.Message |
| 34 | + ) -> None: |
| 35 | + """ |
| 36 | + Removes the spoilers from the message. This command requires the MESSAGE_CONTENT intent to work properly. |
| 37 | +
|
| 38 | + :param interaction: The application command interaction. |
| 39 | + :param message: The message that is being interacted with. |
| 40 | + """ |
| 41 | + spoiler_attachment = None |
| 42 | + for attachment in message.attachments: |
| 43 | + if attachment.is_spoiler(): |
| 44 | + spoiler_attachment = attachment |
| 45 | + break |
| 46 | + embed = discord.Embed( |
| 47 | + title="Message without spoilers", |
| 48 | + description=message.content.replace("||", ""), |
| 49 | + color=0xBEBEFE, |
| 50 | + ) |
| 51 | + if spoiler_attachment is not None: |
| 52 | + embed.set_image(url=attachment.url) |
| 53 | + await interaction.response.send_message(embed=embed, ephemeral=True) |
| 54 | + |
| 55 | + # User context menu command |
| 56 | + async def grab_id( |
| 57 | + self, interaction: discord.Interaction, user: discord.User |
| 58 | + ) -> None: |
| 59 | + """ |
| 60 | + Grabs the ID of the user. |
| 61 | +
|
| 62 | + :param interaction: The application command interaction. |
| 63 | + :param user: The user that is being interacted with. |
| 64 | + """ |
| 65 | + embed = discord.Embed( |
| 66 | + description=f"The ID of {user.mention} is `{user.id}`.", |
| 67 | + color=0xBEBEFE, |
| 68 | + ) |
| 69 | + await interaction.response.send_message(embed=embed, ephemeral=True) |
22 | 70 |
|
23 | 71 | @commands.hybrid_command(
|
24 | 72 | name="help", description="List all commands the bot has loaded."
|
@@ -231,44 +279,6 @@ async def bitcoin(self, context: Context) -> None:
|
231 | 279 | )
|
232 | 280 | await context.send(embed=embed)
|
233 | 281 |
|
234 |
| - @app_commands.context_menu(name="Remove spoilers") |
235 |
| - async def remove_spoilers( |
236 |
| - self, interaction: discord.Interaction, message: discord.Message |
237 |
| - ): |
238 |
| - """ |
239 |
| - Removes the spoilers from the message. This command requires the MESSAGE_CONTENT intent to work properly. |
240 |
| -
|
241 |
| - :param interaction: The application command interaction. |
242 |
| - :param message: The message that is being interacted with. |
243 |
| - """ |
244 |
| - spoiler_attachment = None |
245 |
| - for attachment in message.attachments: |
246 |
| - if attachment.is_spoiler(): |
247 |
| - spoiler_attachment = attachment |
248 |
| - break |
249 |
| - embed = discord.Embed( |
250 |
| - title="Message without spoilers", |
251 |
| - description=message.content.replace("||", ""), |
252 |
| - color=0xBEBEFE, |
253 |
| - ) |
254 |
| - if spoiler_attachment is not None: |
255 |
| - embed.set_image(url=attachment.url) |
256 |
| - await interaction.response.send_message(embed=embed, ephemeral=True) |
257 |
| - |
258 |
| - @app_commands.context_menu(name="Grab ID") |
259 |
| - async def grab_id(self, interaction: discord.Interaction, user: discord.User): |
260 |
| - """ |
261 |
| - Grabs the ID of the user. |
262 |
| -
|
263 |
| - :param interaction: The application command interaction. |
264 |
| - :param user: The user that is being interacted with. |
265 |
| - """ |
266 |
| - embed = discord.Embed( |
267 |
| - description=f"The ID of the user is `{user.id}`.", |
268 |
| - color=0xBEBEFE, |
269 |
| - ) |
270 |
| - await interaction.response.send_message(embed=embed, ephemeral=True) |
271 |
| - |
272 | 282 |
|
273 |
| -async def setup(bot): |
| 283 | +async def setup(bot) -> None: |
274 | 284 | await bot.add_cog(General(bot))
|
0 commit comments