Менеджер по шаблонам Python для вашего бота Discord, чтобы ваши вставки были простыми и последовательными
Используйте следующую команду для установки Embed-Templator в вашу среду Python:
pip install Embed-TemplatorВ зависимости от установки Python, вам может потребоваться использовать одно из следующих.
PIP не на пути, но Python
python -m pip install embed-templatorПитон не на пути
path/to/python.exe -m pip install embed-templatorИспользование нескольких версий Python
py -m pip install embed-templatorСамый простой способ использования встроенного хранителя в вашем проекте - следующее:
from embed_templator import Embed
# Loading your client instance withing the embed templator.
Embed . load ( client )
@ client . command ()
async def ping ( ctx ):
# Use it like a regular Embed.
await ctx . send ( embed = Embed ( description = 'pong!' ))Тем не менее, встроенный матриц может иметь более расширенное использование и использовать контекстные вставки.
from embed_templator import Embed
client = ...
# Note that auto_author requires the ctx to be passed at embeds init.
Embed . load ( client , auto_author = True )
@ client . command ()
async def ping ( ctx ):
# Use it like a regular Embed.
await ctx . send ( embed = Embed ( ctx )( description = 'pong!' ))Если вы используете систему на основе COG, не забудьте инициировать встроенный в свои винтики со следующим:
class MyBeautifulCog ( commands . Cog ):
def __init__ ( self , client ):
self . client = client
Embed . load ( self . client )Тогда вы сможете использовать его, как предыдущие примеры:
@ commands . command ()
async def my ( self , ctx ):
await ctx . send (
embed = Embed ( ctx )( description = "Cabbage" )
)Если вы хотите усовершенствованную конфигурацию встраивания, вы можете создать пользовательский класс Enced, который унаследовал встроенный Templator.
from __future__ import annotations
import embed_templator
class Embed ( embed_templator . Embed ):
def setup ( self ) -> Embed :
return self . set_footer (
text = f" { self . ctx . command } | more info @ { self . ctx . prefix } help"
)| ❗ | В этом примере используется пользовательский CTX, который имеет отслеживание времени! |
|---|
from __future__ import annotations
import embed_templator
class Embed ( embed_templator . Embed ):
def setup ( self ) -> Embed :
return self . set_author (
name = f"Requested by { self . ctx . author } " ,
icon_url = self . ctx . author . avatar_url
)
def update ( self ) -> Embed :
self . set_footer (
icon_url = self . client . user . avatar_url ,
text = ' ' . join (
(
f" { self . ctx . time . elapsed () } " ,
f"⏳ { self . client . latency } " ,
f"? { self . ctx . prefix } help" ,
)
)
)
return selfСпасибо, что использовали Embed-Templator!
© 2020 copyright Edhyjox
Этот репозиторий лицензирован по лицензии MIT. Смотрите лицензию для деталей.