Search code examples
pythonnextcord

Sending Images with nextcord (Application didn't respond)


Im trying to send a image but when I send only the image it sends the image and then says that the application didn't respond I tried sending a ephemeral message but to me it looks kind of messy

@slash_command(name='somename', description='description', guild_ids=[id])
async def text(self, ctx : Interaction):
    channel = ctx.channel
    await ctx.response.send_message("somemessage", ephemeral=True)
    await channel.send(file=nextcord.File('somepicture.png'))

Solution

  • This is because the interaction need to be acknowledged by your bot.

    you can do this by using .defer optional you can deleting the last message

    @slash_command()
    async def image(self, interaction : Interaction):
        await interaction.response.defer()
        message = await interaction.channel.fetch_message(int(interaction.channel.last_message_id))
        await interaction.channel.send("somemessage", files=[nextcord.File('somepicture.png')])
        await message.delete()