Add delete method to Message (#21)

This commit is contained in:
Slipstream 2025-06-10 15:56:00 -06:00 committed by GitHub
parent e9375a5a36
commit feb806cc05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View File

@ -311,6 +311,13 @@ class HTTPClient:
"GET", f"/channels/{channel_id}/messages/{message_id}"
)
async def delete_message(
self, channel_id: "Snowflake", message_id: "Snowflake"
) -> None:
"""Deletes a message in a channel."""
await self.request("DELETE", f"/channels/{channel_id}/messages/{message_id}")
async def create_reaction(
self, channel_id: "Snowflake", message_id: "Snowflake", emoji: str
) -> None:

View File

@ -7,6 +7,7 @@ Data models for Discord objects.
import json
import asyncio
import aiohttp # pylint: disable=import-error
import asyncio
from typing import Optional, TYPE_CHECKING, List, Dict, Any, Union
from .errors import DisagreementException, HTTPException
@ -199,6 +200,22 @@ class Message:
view=view,
)
async def delete(self, delay: Optional[float] = None) -> None:
"""|coro|
Deletes this message.
Parameters
----------
delay:
If provided, wait this many seconds before deleting.
"""
if delay is not None:
await asyncio.sleep(delay)
await self._client._http.delete_message(self.channel_id, self.id)
def __repr__(self) -> str:
return f"<Message id='{self.id}' channel_id='{self.channel_id}' author='{self.author!r}'>"