【发布时间】:2022-08-14 11:00:55
【问题描述】:
我将如何在 cogs 中使用interactions.py?我希望每个命令都有不同的文件,但我不确定如何使用interactions.py 来做到这一点。
标签: python python-3.x discord discord.py
我将如何在 cogs 中使用interactions.py?我希望每个命令都有不同的文件,但我不确定如何使用interactions.py 来做到这一点。
标签: python python-3.x discord discord.py
我们为此使用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)
您可以查看文档here。
【讨论】: