【问题标题】:Sending Msg to the channel in cinch bot framework在 cinch bot 框架中将消息发送到通道
【发布时间】:2014-01-30 19:25:44
【问题描述】:

我刚开始使用这个 cinch gem 并使用这个框架来开发一个机器人。

面临一个问题。我想在有人加入频道时自动向频道发送消息

谁能帮我解决这个问题。

代码:

listen_to :join, method: :on_join
    def on_join(m)
      post_message(options(m,
          opcode: 'join',
          nick:   m.user.nick,
          line:   "#{m.user.nick} use this link to get more info"))

请您检查一下并告诉我是否缺少任何内容。

【问题讨论】:

  • 你能解释一下你尝试的时候出了什么问题吗?我可以看到 def 缺少 end 但不确定这是否是您的问题
  • 你好,什么都没有发生意味着它不会在加入时打招呼。

标签: ruby cinch


【解决方案1】:

我不确定您的 post_message 命令是什么,但如果它是您在 Cinch 中找到的,请不要使用它。相反,使用内置命令来响应消息

 def on_join(m)
   # Don't greet the bot.
   unless m.user == @bot
   # Reply to the user who joined, the true prepends the line with the user's name
   m.reply "Use this link to get more info - http://whatever", true
 end

然后:

 15:30 -!- Irssi: #bottest: Total of 2 nicks [0 ops, 0 halfops, 0 voices, 2 normal]
 15:30 -!- Channel #bottest created Mon Feb 24 15:30:17 2014
 15:30 < bot> user: Use this link to get more info - http://whatever

【讨论】:

    猜你喜欢
    • 2017-04-08
    • 2017-08-20
    • 2018-07-22
    • 2020-08-25
    • 1970-01-01
    • 2023-03-27
    • 2019-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多