set_embed_color, embed_color and get_message added #23
| @@ -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 | ||||
|   Same here, do not use env vars Same here, do not use env vars | ||||
|         else: | ||||
|             try: | ||||
|                 HEX = re.compile(r'^(#)[A-Fa-f0-9]{6}$') | ||||
|   Why are you compiling this regex per invoke, store global. Why are you compiling this regex per invoke, store global. | ||||
|                 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 | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	
No, never use env vars like this, instead store this under
discord.Embed.default_colour