1 Commits

Author SHA1 Message Date
c079983c57 set_embed_color, embed_color and get_message added 2021-08-29 00:56:09 +01:00
2 changed files with 55 additions and 3 deletions

View File

@ -1,8 +1,8 @@
blank_issues_enabled: true
blank_issues_enabled: false
contact_links:
- name: Ask a question
about: Ask questions and discuss with other users of the library.
url: https://github.com/iDevision/enhanced-discord.py/issues/new
url: https://github.com/Rapptz/discord.py/discussions
- name: Discord Server
about: Use our official Discord server to ask for help and questions as well.
url: https://discord.gg/TvqYBrGXEm
url: https://discord.gg/r3sSKJJ

View File

@ -241,6 +241,58 @@ class Client:
# internals
def get_message(self, id):
"""Get a message from cache if the message is still in cache.
.. versionadded:: 1.6.0.7
Parameters
-----------
id: :class:`int`
The message ID to look for.
Returns
--------
Optional[:class:`.Message`]
The message asked for."""
return utils.get(self.cached_messages, id=id)
@property
def embed_color(self):
"""Optional[:class:`.Colour`]: The default embed colour that is
being used for all embed if no colour is passed."""
col = os.getenv("DEFAULT_EMBED_COLOR")
if not col:
return None
return Colour(int(col, 16))
def set_embed_color(self, color):
"""Set a new default embed color.
This will raise a TypeError if an improper format was passed.
.. versionadded:: 1.5.0.1
Parameters
-----------
color: Union[:class:`.Colour`, :class:`int`]
The new color you want to set as default embed color.
Pass either an instance of discord.Color or a valid
0x****** HEX value.
Returns
--------
:class:`.Colour`
The new color that has been set as default embed color.
"""
if isinstance(color, (Color, Colour)):
os.environ['DEFAULT_EMBED_COLOR'] = str(hex(color))
return color
else:
try:
HEX = re.compile(r'^(#)[A-Fa-f0-9]{6}$')
col = Color(color)
if HEX.match(str(col)):
os.environ['DEFAULT_EMBED_COLOR'] = str(hex(col))
return col
else:
raise TypeError('The hex value passed could not be converted to a color')
except:
raise TypeError('embed_color must be an instance of discord.Colour or a valid 0x****** hex value.')
def _get_websocket(self, guild_id: Optional[int] = None, *, shard_id: Optional[int] = None) -> DiscordWebSocket:
return self.ws