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

discord.py中修改斜杠命令处理过程提示文本的方法咨询

discord.py中修改斜杠命令处理过程提示文本的方法咨询

嘿,别担心你的问题表述不清,我完全明白你想实现什么效果!在discord.py里是完全可以做到把默认的“Sending command”提示改成类似“Bot Thinking…”这样的文本的,具体操作很简单:

在你的斜杠命令回调函数里,第一时间调用await interaction.response.defer(thinking=True),这样Discord就会把原来的默认提示替换成“Bot is thinking…”(和你想要的“Bot Thinking…”几乎一致)。

举个简单的代码例子:

import discord
from discord import app_commands
import asyncio

# 假设你已经初始化了bot和tree对象
@tree.command(name="test_command", description="测试自定义思考提示")
async def test_command(interaction: discord.Interaction):
    # 先调用defer,触发思考提示
    await interaction.response.defer(thinking=True)
    # 这里模拟耗时的处理过程,比如调用API、复杂计算等
    await asyncio.sleep(3)
    # 处理完成后发送最终回复
    await interaction.followup.send("处理完成啦!")

如果你的discord.py版本是v2.x及以上,这个方法完全适用。要是你想更个性化的提示文本,还可以先发送一条临时消息(比如await interaction.response.send_message("Bot Thinking…", ephemeral=True)),然后在处理完成后编辑这条消息——不过这种方式是静态可编辑消息,而非动态加载状态,你可以根据需求选择。

备注:内容来源于stack exchange,提问作者Bohdan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.23 07:03:02