@@ -1529,6 +1529,59 @@ async def pins(self) -> List[Message]:
1529
1529
state = self ._state
1530
1530
data = await state .http .pins_from (channel .id )
1531
1531
return [state .create_message (channel = channel , data = m ) for m in data ]
1532
+
1533
+ def can_send (self , * objects ) -> bool :
1534
+ """Returns a :class:`bool` indicating whether you have the permissions to send the object(s).
1535
+
1536
+ Raises
1537
+ ------
1538
+ TypeError
1539
+ An invalid type has been passed.
1540
+
1541
+ Returns
1542
+ --------
1543
+ :class:`bool`
1544
+ Indicates whether you have the permissions to send the object(s).
1545
+ """
1546
+ mapping = {
1547
+ 'Message' : 'send_messages' ,
1548
+ 'Embed' : 'embed_links' ,
1549
+ 'File' : 'attach_files' ,
1550
+ 'Emoji' : 'use_external_emojis' ,
1551
+ 'GuildSticker' : 'use_external_stickers' ,
1552
+ }
1553
+ # Can't use channel = await self._get_channel() since its async
1554
+ if hasattr (self , 'permissions_for' ):
1555
+ channel = self
1556
+ elif hasattr (self , 'channel' ) and not type (self .channel ).__name__ in ('DMChannel' , 'GroupChannel' ):
1557
+ channel = self .channel
1558
+ else :
1559
+ return True # Permissions don't exist for User DMs
1560
+
1561
+
1562
+ objects = (None , ) + objects # Makes sure we check for send_messages first
1563
+
1564
+ for obj in objects :
1565
+ try :
1566
+ if obj is None :
1567
+ permission = mapping ['Message' ]
1568
+ else :
1569
+ permission = mapping .get (type (obj ).__name__ ) or mapping [obj .__name__ ]
1570
+
1571
+ if type (obj ).__name__ == 'Emoji' :
1572
+ if obj ._to_partial ().is_unicode_emoji or obj .guild_id == channel .guild .id :
1573
+ continue
1574
+ elif type (obj ).__name__ == 'GuildSticker' :
1575
+ if obj .guild_id == channel .guild .id :
1576
+ continue
1577
+
1578
+ except (KeyError , AttributeError ):
1579
+ raise TypeError (f'The object { obj } is of an invalid type.' )
1580
+
1581
+ if not getattr (channel .permissions_for (channel .guild .me ), permission ):
1582
+ return False
1583
+
1584
+ return True
1532
1585
1533
1586
def history (
1534
1587
self ,
0 commit comments