Earl Watkins
Earl Watkins

Reputation: 13

Send Images with Hikari Python

I made a function to send an image on invocation but instead it ends up sending 'attachment://img.jpg'

here's the function :

@bot.command
@lightbulb.command('img', 'Test command')
@lightbulb.implements(lightbulb.SlashCommand)   
async def imgsnd(ctx):
    filename = 'img.jpg'
    with open(filename, "rb") as fh:
        f = hikari.File('/Users/admin/Desktop/Bot/'+filename)
    await ctx.respond(f)
        

Upvotes: 0

Views: 1499

Answers (1)

davfsa
davfsa

Reputation: 21

Sending attachments as a slash command initial response wasnt supported until 2.0.0.dev106. Consider upgrading and the issue will be solved.

Additionally, even tho this wasn't part of the question, just a pointer. That open is not necessary and, on top of that, blocking. Instead, you can reduce your code to this:

@bot.command
@lightbulb.command('img', 'Test command')
@lightbulb.implements(lightbulb.SlashCommand)   
async def imgsnd(ctx):
    f = hikari.File('/Users/admin/Desktop/Bot/img.jpg')
    await ctx.respond(f)

Upvotes: 1

Related Questions