Embed Templator
Embed Templator
您的Discord機器人的Python模板管理器,以使您的嵌入簡單且一致
使用以下命令將嵌入式設備安裝到您的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!' ))但是,嵌入模板可以具有更高級的用法,並使用上下文嵌入。
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
該存儲庫是根據MIT許可證獲得許可的。有關詳細信息,請參見許可證。