简体   繁体   English

制作 Ruby 电报机器人时出现需求问题

[英]Problem with require while making a Ruby telegram bot

I was doing a code in the app "Atom" and when I tried to run this code我正在应用程序“Atom”中编写代码,当我尝试运行此代码时

require 'telegram_bot'

token = 'MY_TOKEN'

bot = TelegramBot.new(token: token)

bot.get_updates(fail_silently: true) do |message|
  puts "@#{message.from.username}: #{message.text}"
  command = message.get_command_for(bot)

  message.reply do |reply|
    case command
    when / start /i
      reply.text = 'Ciao, questo è un bot creato da @JustDavide per gli strike. Usami con /strike (Username) (motivo) (numero strike)'
    end
    puts "sending #{reply.text.inspect} to @#{message.from.username}"
    reply.send_with(bot)
  end
end

Obviously I made another file "Gemfile" putting显然我制作了另一个文件“Gemfile”

source 'https://rubygems.org'
gem 'telegram_bot'

And when I use "Atom Runner" this error comes:当我使用“Atom Runner”时,会出现这个错误:

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- telegram_bot (LoadError)
    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/davidelao/telegram-bot/bot.rb:1:in `<main>'

I started Ruby like 3 weeks ago, so I am not an expert我像 3 周前一样开始了 Ruby,所以我不是专家

First of all首先

cd path/to/my_app
bundle install

Then try to run your code from console to see if error occurs然后尝试从控制台运行您的代码以查看是否发生错误

cd path/to/my_app
bundle exec ruby my_script_with_telegram.rb

if it is ok, then we need more information for your Atom Runner cause error lies in it如果没问题,那么我们需要有关您的Atom Runner的更多信息,因为错误在于它

I think that this gem is not installed.我认为这个 gem 没有安装。 You can try these commands:您可以尝试以下命令:

gem install telegram_bot宝石安装电报机器人

bundle install捆绑安装

It's ok now.. I'm using Repl now not Atom, it was giving me some problems and now I'm ok with that site.现在好了..我现在使用的是 Repl 而不是 Atom,这给我带来了一些问题,现在我可以使用该站点了。 Thanks to everyone anyway!总之谢谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM