Skip to content

Undefined local variable or method 'sessions' #2

Closed
@Dielerorn

Description

@Dielerorn

When I start and run this bot, it runs perfectly, but when I send a message in the channel, I get this error:
Exception: #<NameError: undefined local variable or method "sessions" for Bot::DiscordEvents::DialogflowEvent:Module>

My code looks like this:

module Bot::DiscordEvents
  module DialogflowEvent
    extend Discordrb::EventContainer
    message do |event|
      if event.server && !event.author.roles.any?
        str = "#{event.channel.id}_CLIENT_TOKEN"
        if ENV[str]
          if !sessions[event.channel.id]
            sessions[event.channel.id] = ApiAiRuby::Client.new( :client_access_token => ENV[str] )
          end
          response = sessions[event.channel.id].text_request event.message.content[0,255]
          speech = response[:result][:fulfillment][:speech]
          if speech && !speech.empty?
            event.channel.start_typing
            sleep 1
            event.respond "#{speech}"
          end
        end
      end
    end
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions