مدير قالب Python لبروتك في Discord للحفاظ على تضميناتك بسيطة ومتسقة
استخدم الأمر التالي لتثبيت empled-themplator في بيئة Python الخاصة بك:
pip install Embed-Templatorاعتمادًا على تثبيت Python الخاص بك ، قد تحتاج إلى استخدام واحدة مما يلي.
PIP ليس في الطريق ولكن Python هو
python -m pip install embed-templatorPython ليس في الطريق
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!' ))ومع ذلك ، يمكن أن يكون لدى Templator التضمين استخدام أكثر تقدماً ، ويستخدم التضمينات السياق.
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" )
)إذا كنت ترغب في تكوين تضمين متقدم ، فيمكنك إنشاء فئة مخصصة مخصصة ترث المعبد المدمج.
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شكرا لاستخدام التضمين!
© 2020 copyright Edhyjox
تم ترخيص هذا المستودع بموجب ترخيص معهد ماساتشوستس للتكنولوجيا. انظر الترخيص للحصول على التفاصيل.