Pycord Slash 命令通过嵌入进行响应

发布于 2025-01-12 14:04:06 字数 730 浏览 3 评论 0原文

我有以下 Pycord 斜杠命令

@commands.slash_command(name="testcmd")
@commands.has_permissions(administrator=True)
async def SampleSlashComand(self, ctx: commands.Context,
                       title: Option(str, "title", required=True),
                       description: Option(str, "description", required=True),
                       ):
    await ctx.defer()

    if title == "test":
        return await ctx.respond("hi")

    embed = discord.Embed(
        title=f"{title}",
        description=f"{description}",
        timestamp=datetime.now()
    )
    return await ctx.respond(embed=embed)

当运行“标题”设置为“测试”的斜杠命令时,我看到机器人的响应“hi”。但是,当我使用另一个标题(导致发布嵌入)时,机器人会响应错误“交互应用程序命令无效”

是否可以通过嵌入响应斜杠命令?

I have the following Pycord slash command

@commands.slash_command(name="testcmd")
@commands.has_permissions(administrator=True)
async def SampleSlashComand(self, ctx: commands.Context,
                       title: Option(str, "title", required=True),
                       description: Option(str, "description", required=True),
                       ):
    await ctx.defer()

    if title == "test":
        return await ctx.respond("hi")

    embed = discord.Embed(
        title=f"{title}",
        description=f"{description}",
        timestamp=datetime.now()
    )
    return await ctx.respond(embed=embed)

When running the slash command with 'title' set to "test", I see the respone "hi" from the bot. However when I use another title, which causes an embedding to be posted, the bot responds with the error "Invalid interaction application command"

Is it possible to have a slash command be responded with a embedding?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔落墨 2025-01-19 14:04:06

我不是 100% 确定这是否是答案,但问题似乎是我实际上有 2 个机器人使用相同的“令牌”和斜杠命令运行。自从我意识到并关闭重复的机器人后,一切都按预期工作,这似乎搞砸了一些事情。

也许这是斜线命令的一个缺点,只有一个正在运行的机器人才能真正处理它

Im not 100% sure if this is the answer or not but it appears the issue was that I actually had 2 bots running with the same "token" and slash command. This seems to have messed something up since when I realized and shutdown the duplicate bot everything worked as expected.

Maybe this is the one downside to slash commands, only one bot running can really handle it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文