2017-06-10 48 views
1

我正在使用Discordrb Api編碼Discord Bot,而且我無法找到一種方法來在我的計算機上共享圖像以進行不一致的聊天,這就是爲什麼我在這裏問你,我希望你能找到回答。如何與Discordrb Api共享圖像?

這裏是我的實際代碼:

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

好了,所以我已經找到一種方法來做到這一點

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 

我希望這可以幫助一些人。