Embed Templator
Embed Templator
埋め込みをシンプルで一貫性に保つために、DiscordボットのPythonテンプレートマネージャー
次のコマンドを使用して、埋め込みテンプレーターをPython環境にインストールします。
pip install Embed-TemplatorPythonのインストールに応じて、次のいずれかを使用する必要がある場合があります。
ピップはパスにはありませんが、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!' ))コグベースのシステムを使用している場合は、次のようなコグに埋め込まれたことを忘れないでください。
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" )
)Advanced Embed構成が必要な場合は、埋め込まれたテンプレーターを継承するカスタム埋め込みクラスを作成できます。
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 selfEmbed-Templatorを使用してくれてありがとう!
© 2020 copyright Edhyjox
このリポジトリは、MITライセンスの下でライセンスされています。詳細については、ライセンスを参照してください。