pythonpycord

How to respond to slash command in different channel?


I'm using slash commands in pycord. Normally, to respond to a user's command, one can use the ctx.respond method, like so:

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

But what if I want to reply in another channel? I'm aware I can use ctx.channel.send but this does not count as a response, triggering a "The application did not respond" warning in discord:

enter image description here

So how can I respond in a different channel in the proper way? Or is there a way to just make an empty response in the original channel, which means I'm free to use ctx.channel.send to send a message in the channel of my choice?


Solution

  • You should not be aiming to respond in a different channel for the sake of user experience, as this could be confusing.

    Similarly, there is no option to send an empty response.

    The best way to tackle this would be to respond to the interaction with a message (which could be ephemeral), notifying the user that a message has been posted in another channel. E.g.

    @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!")