You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Disnake斜杠命令设置为仅执行者可见?

实现Disnake斜杠命令回复仅对执行者可见

要让generate_password命令的回复仅被执行命令的用户看到,只需在inter.response.send_message()中添加ephemeral=True参数即可。这个参数会将消息设置为临时消息,仅触发命令的用户能看到,其他成员无法查看。

修改后的完整代码:

import disnake
from disnake.ext import commands

intents = disnake.Intents.default()
intents.members = True
intents.message_content = True

bot = commands.Bot(command_prefix=commands.when_mentioned_or("!"), intents=intents)

@bot.slash_command()
async def generate_password(inter):
    # 添加ephemeral=True参数,让回复仅对执行者可见
    await inter.response.send_message("password", ephemeral=True)
    
@bot.event
async def on_ready():
    print(f"Logged in as {bot.user} (ID: {bot.user.id})\n------")

bot.run("token")

补充说明

  • 临时消息会在用户切换频道、重启客户端或一段时间后自动消失,也可由用户手动关闭
  • 这种方式适合发送密码、个人通知等敏感内容,有效避免信息泄露

内容的提问来源于stack exchange,提问作者ethionamide

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 11:40:29