63
63
'GuildChannel' ,
64
64
'Messageable' ,
65
65
'Connectable' ,
66
+ 'Mentionable'
66
67
)
67
68
68
69
T = TypeVar ('T' , bound = VoiceProtocol )
@@ -1142,6 +1143,7 @@ class Messageable:
1142
1143
- :class:`~discord.Member`
1143
1144
- :class:`~discord.ext.commands.Context`
1144
1145
- :class:`~discord.Thread`
1146
+ - :class:`~discord.ApplicationContext`
1145
1147
"""
1146
1148
1147
1149
__slots__ = ()
@@ -1528,6 +1530,59 @@ async def pins(self) -> List[Message]:
1528
1530
state = self ._state
1529
1531
data = await state .http .pins_from (channel .id )
1530
1532
return [state .create_message (channel = channel , data = m ) for m in data ]
1533
+
1534
+ def can_send (self , * objects ) -> bool :
1535
+ """Returns a :class:`bool` indicating whether you have the permissions to send the object(s).
1536
+
1537
+ Raises
1538
+ ------
1539
+ TypeError
1540
+ An invalid type has been passed.
1541
+
1542
+ Returns
1543
+ --------
1544
+ :class:`bool`
1545
+ Indicates whether you have the permissions to send the object(s).
1546
+ """
1547
+ mapping = {
1548
+ 'Message' : 'send_messages' ,
1549
+ 'Embed' : 'embed_links' ,
1550
+ 'File' : 'attach_files' ,
1551
+ 'Emoji' : 'use_external_emojis' ,
1552
+ 'GuildSticker' : 'use_external_stickers' ,
1553
+ }
1554
+ # Can't use channel = await self._get_channel() since its async
1555
+ if hasattr (self , 'permissions_for' ):
1556
+ channel = self
1557
+ elif hasattr (self , 'channel' ) and not type (self .channel ).__name__ in ('DMChannel' , 'GroupChannel' ):
1558
+ channel = self .channel
1559
+ else :
1560
+ return True # Permissions don't exist for User DMs
1561
+
1562
+
1563
+ objects = (None , ) + objects # Makes sure we check for send_messages first
1564
+
1565
+ for obj in objects :
1566
+ try :
1567
+ if obj is None :
1568
+ permission = mapping ['Message' ]
1569
+ else :
1570
+ permission = mapping .get (type (obj ).__name__ ) or mapping [obj .__name__ ]
1571
+
1572
+ if type (obj ).__name__ == 'Emoji' :
1573
+ if obj ._to_partial ().is_unicode_emoji or obj .guild_id == channel .guild .id :
1574
+ continue
1575
+ elif type (obj ).__name__ == 'GuildSticker' :
1576
+ if obj .guild_id == channel .guild .id :
1577
+ continue
1578
+
1579
+ except (KeyError , AttributeError ):
1580
+ raise TypeError (f'The object { obj } is of an invalid type.' )
1581
+
1582
+ if not getattr (channel .permissions_for (channel .guild .me ), permission ):
1583
+ return False
1584
+
1585
+ return True
1531
1586
1532
1587
def history (
1533
1588
self ,
@@ -1691,4 +1746,4 @@ async def connect(
1691
1746
1692
1747
class Mentionable :
1693
1748
# TODO: documentation, methods if needed
1694
- pass
1749
+ pass
0 commit comments