我正在使用Discordrb Api对Discord Bot进行编码,我无法找到一种方法在我的计算机上共享图像到不和谐聊天,这就是为什么我在这里问你,我希望你能找到答案。
这是我的实际代码:
bot.command :food do |event|
agent = Mechanize.new
link = 'https://source.unsplash.com/random/featured/?Food'
agent.get(link).save "images/pic.jpg"
end
答案 0 :(得分:1)
好的,所以我找到了办法
bot.command :food do |event|
agent = Mechanize.new
link = 'https://source.unsplash.com/random/featured/?Food,Plate'
agent.get(link).save "pic.png"
event.send_file(File.open('pic.png', 'r'), caption: "Voiçi votre repas #
{event.user.name} .")
sleep(5)
event File.delete("pic.png")
end
我希望这可以帮助一些人。
答案 1 :(得分:0)
我想补充一下这个问题,如果您要发送在线存储的图像,则可能只想嵌入即可。
bot.command :food do |event|
event.channel.send_embed("Check out the image below") do |embed|
embed.image = Discordrb::Webhooks::EmbedImage.new(url: "https://source.unsplash.com/random/featured/?Food,Plate")
end
end