[英]How do you make cogs in interactions.py?
如何在 discord.py 中制作齒輪,但在interactions.py 中?
我基本上想為每個命令有一個單獨的 python 文件,並讓它們全部加載到 main.py 中......但我不知道你在 python 文件中需要什么實際命令。
我希望我知道,我一直試圖找出同樣的事情一段時間。
我們為此使用Extension
。 這是在 discord.py 中使用Extension
(又名 Cogs)的示例。
機器人主文件:
import interactions
client = interactions.Client(...)
client.load("ext1")
client.command(
name="command_outside",
description"This command is in main bot file",
)
async def _command_outside(ctx: interactions.CommandContext):
await ctx.send("This command is ran outside of Extension.")
client.start()
ext1.py 文件,它是擴展,又名 Cogs。
import interactions
class Ext(interactions.Extension):
def __init__(self, client: interactions.Client) -> None:
self.client: interactions.Client = client
@interactions.extension_command(
name="command_in_ext",
description"This command is in an Extension",
)
async def _ext_command(self, ctx: interactions.CommandContext):
await ctx.send("This command is ran inside an Extension")
def setup(client):
Ext(client)
請注意,您需要更改命令裝飾器,因為像@client.command()
或@client.component()
這樣的東西在 Extension 中不起作用。
您可以在此處查看文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.