代码之家  ›  专栏  ›  技术社区  ›  As2Bax

discord.py-如何使斜杠命令的响应只对我可见?

  •  1
  • As2Bax  · 技术社区  · 2 年前

    小问题。 如何使斜杠命令仅对我可见? 照片: example

    在互联网上搜索了10分钟,没有找到答案。我唯一发现的是如何制作斜杠命令。有人知道怎么做吗?谢谢

    1 回复  |  直到 2 年前
        1
  •  1
  •   Rexy    2 年前
    @bot.tree.command(name="something")
    async def something(interaction:discord.Interaction):
        await interaction.response.send_message("NOTHING",ephemeral=True)
        # optional (if you want to edit the response later,delete it, or send a followup)
        await interaction.edit_original_response(content="Something")
        await interaction.followup.send("This is a message too.",ephemeral=True)
        await interaction.delete_original_response()
        # if you have deleted the original response you can't edit it or send a followup after it
    

    这些都是基础。如果您不知道如何加载命令:

    @bot.event
    async def on_ready():
        print("Bot is online!")
        try:
            synced = await bot.tree.sync()
            print(f"Synced {len(synced)} commands.")
        except Exception as e:
            print(e)
    

    一切就绪!祝编码好运。如果你需要进一步的帮助,我的意见是@rexy.py