如何在discord.py上编写组应用程序命令

问题描述 投票:0回答:1

我一直在寻找如何对应用程序(交互)命令进行分组一段时间,但没有找到任何解决方案。

我希望当我在 Discord bot 上使用“/say”时,它会显示两个选项“/say message”和“/say embed”,但我还没有找到任何解决方案。

有人知道我应该做什么吗?

我似乎无法理解discord.py 文档。

python discord discord.py bots
1个回答
0
投票

一个简单的方法,至少对我来说,就是将类名设为你想要的单词,然后添加斜杠命令。

示例:

import discord
from discord.ext import commands
from discord import app_commands

class say(commands.GroupCog):
    def __init__(self, client: commands.Bot):
        self.client = client (client or bot depending on which you use)



    @app_commands.command(name="message")
    async def message()
      .....

    @app_commands.command(name="embed")
    async def embed()
      ....

在示例中我使用

@app_commands
,因为我从主 python 文件的不同文件中提取了示例。

基本上,您在 groupcog 下使用的任何命令都会自动采用 cog 的名称,后跟命令名称。

© www.soinside.com 2019 - 2024. All rights reserved.