Utils¶
Some utility functions for Discord and Python.
- ezcord.utils.create_json_file(dictionary, filename='data.json', *, indent=2, description=None, spoiler=False, **kwargs)[source]¶
Create a
discord.File
object from a dictionary.- Parameters:
dictionary (
dict
) – The dictionary to convert to a JSON file.filename (
str
) – The filename to use for the JSON file.indent (
int
) – The indent to use for the JSON file.description (
str
|None
) – The description to use for the discord file.spoiler (
bool
) – Whether the Discord file should be a spoiler.**kwargs – Additional keyword arguments for
json.dumps()
.
- Return type:
- ezcord.utils.create_text_file(text, filename='data.txt', **kwargs)[source]¶
Create a
discord.File
object from a string.- Parameters:
text (
str
) – The string to convert to a text file.filename (
str
) – The filename to use for the text file.**kwargs – Keyword arguments for
discord.File
.
- Return type:
- ezcord.utils.create_html_file(html, filename='data.html', **kwargs)[source]¶
Create a
discord.File
object from an HTML string.- Parameters:
html (
str
) – The HTML string to convert to an HTML file.filename (
str
) – The filename to use for the HTML file.**kwargs – Keyword arguments for
discord.File
.
- Return type:
- ezcord.utils.codeblock(content, *, lang='yaml', unit='', interaction=None)[source]¶
Returns a codeblock with the given content.
- Parameters:
content (
int
|str
) – The content of the codeblock. If the content is an integer, it will be formatted with commas (or dots if the language is German).lang (
str
) – The language of the codeblock. Defaults toyaml
.unit (
str
) – The text to display after the given content. This is only used if the content is an integer.interaction (
Interaction
|None
) – The interaction to get the language from. Defaults toNone
. If not provided, the language will be set to the default language. The language will determine how large numbers are formatted.
- Return type:
- ezcord.utils.ez_autocomplete(values)[source]¶
A similar function as
basic_autocomplete()
, but instead of returning options starting with the user’s value, it returns options containing the user’s value.- Parameters:
values (Iterable[str]) – Accepts an iterable of
str
, a callable (sync or async) that takes a single argument ofAutocompleteContext
, or a coroutine. Must resolve to an iterable ofstr
.
- ezcord.utils.count_lines(directory=None, *, count_empty_lines=True, include_hidden=False, ignored_dirs=None, ignored_files=None)[source]¶
Counts the total amount of lines in all Python files in the given directory.
- Parameters:
directory (
str
|None
) – The directory to count the lines in. Defaults to the current working directory.count_empty_lines (
bool
) – Whether to count empty lines. Defaults toTrue
.include_hidden (
bool
) – Whether to include directories starting with a dot. Defaults toFalse
.ignored_dirs (
list
[str
] |None
) – A list of directories to ignore. By default, venv folders and folders starting with a dot are ignored.ignored_files (
list
[str
] |None
) – A list of file patterns to ignore.
- Return type:
- async ezcord.utils.load_message(obj, message_url, error=False)[source]¶
Get a message from a message URL.
- Parameters:
- Raises:
InvalidFormat – The message URL is invalid.
MissingPermission – The bot does not have permissions to access the channel.
ChannelNotFound – The channel was not found.
MessageNotFound – The message couldn’t be found in the given channel, perhaps it was deleted.
- Return type: