我正在用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发布于 2017-06-11 18:01:40
好的,我已经找到了一种方法
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我希望这能帮助一些人。
Channel#send_file
发布于 2019-10-30 21:24:25
我想补充这个问题的答案,如果你要发送一个存储在网上的图像,你可能只想简单地发送一个嵌入。
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
endChannel#send_embed
Embed
https://stackoverflow.com/questions/44478224
复制相似问题