Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

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

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

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

And when I use "Atom Runner" this error comes:

/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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...