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许可证获得许可的。有关详细信息,请参见许可证。