shardlab / discordrb

Discord API for Ruby

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Respond with image for slash command

OnlyReFLeX opened this issue · comments

Trying to reply with image for slash command

# example
bot.application_command(:profile) do |event|
  event.respond(content: 'test') do |builder|
    builder.file = File.open('./test.png') # doesn't work (no error)
    builder.attachments = [File.open('./test.png')] # error (undefined method)
  end

  event.send_file # doesn't exist
end 

But there is no functional for that, Is there any way to do this?

commented

Interaction response API endpoint allows attachments.

This is a workaround that may suit your needs.

base64_image_content = '...'
image = StringIO.new(Base64.decode64(base64_image_content))
# OR
image = File.open('./test.png', 'r')
@event.channel.send_file(
  image,
  caption: caption,
  filename: filename
)