如何在不同频道中响应斜杠命令?

0 投票
1 回答
20 浏览
提问于 2025-04-12 04:53

我在使用pycord的斜杠命令。通常,要回应用户的命令,可以使用ctx.respond这个方法,像这样:

@bot.slash_command(description="Say hello.")
async def say_hello(ctx: ApplicationContext) -> None:
    ctx.respond("Hello!")

但是如果我想在另一个频道回复呢?我知道可以用ctx.channel.send,但这样做不会被算作回应,会在Discord里触发一个“应用没有回应”的警告:

这里插入图片描述

那么,我该如何在不同的频道正确地回应呢?或者有没有办法在原来的频道发一个空的回应,这样我就可以自由地使用ctx.channel.send在我选择的频道发送消息?

1 个回答

1

你不应该为了用户体验而在不同的频道回复,因为这样可能会让人感到困惑。

同样,也没有办法发送一个空的回复。

解决这个问题的最好方法是用一条消息来回应用户的互动(这条消息可以是暂时的),告诉用户在另一个频道里已经发布了一条消息。

例如:

@bot.slash_command(description="Say hello.")
async def say_hello(ctx: ApplicationContext) -> None:
    my_channel = bot.get_channel(my_channel_id)
    await ctx.send_response("Your hello has been sent to " + my_channel.mention, ephemeral=True)
    
    await my_channel.send("Hello in another channel!")

撰写回答