ตัวจัดการเทมเพลต Python สำหรับบอท Discord ของคุณเพื่อให้การฝังของคุณง่ายและสอดคล้องกัน
ใช้คำสั่งต่อไปนี้เพื่อติดตั้ง Embed-templator ลงในสภาพแวดล้อม Python ของคุณ:
pip install Embed-Templatorขึ้นอยู่กับการติดตั้ง Python ของคุณคุณอาจต้องใช้หนึ่งในสิ่งต่อไปนี้
PIP ไม่ได้อยู่ในเส้นทาง แต่ Python คือ
python -m pip install embed-templatorPython ไม่ได้อยู่ในเส้นทาง
path/to/python.exe -m pip install embed-templatorใช้หลายรุ่นงูหลาม
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" )
)หากคุณต้องการการกำหนดค่าฝังขั้นสูงคุณสามารถสร้างคลาสฝังตัวที่กำหนดเองที่จะสืบทอดตัวกระตุ้นการฝังตัว
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 ดูใบอนุญาตสำหรับรายละเอียด