【问题标题】:(Python, Twitch Bot) Having troubles implementing AutoMod(Python、Twitch Bot)在实现 AutoMod 时遇到问题
【发布时间】:2021-08-30 18:33:43
【问题描述】:

我目前正在为我的直播编写一个 Twitch 审核机器人,但我遇到了一些问题 - 它的自动模组部分无法正常工作。我根本不知道是什么让它不起作用。

这是我的代码:

@bot.event()
async def event_message(message):
  print(f"Message detected:\nSender: {message.author.name}\nContent: {message.content}")


  for word in banned_words:
    if word in message.content.lower():
      print("I deleted that message.")
    
      await message.send(f"/timeout {message.author.name} 3s You sent a non-family-friendly word, but we're a family-friendly channel.")
      await message.send("f ¦ [Purge, 3s TO]")

这就是控制台中出现的内容:

Message detected:
Sender: slend_k
Content: [the swear word I sent - I changed it because, well, it's a swear]
I deleted that message.
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/twitchio/client.py", line 190, in wrapped
    await func(*args)
  File "main.py", line 28, in event_message
    await message.send(f"/timeout {message.author.name} 3s You sent a non-family-friendly word, but we're a family-friendly channel.")
AttributeError: 'Message' object has no attribute 'send'

我不知道是什么导致了这个问题,因为我知道message 确实具有send 属性。 我用ctx.send 尝试过,但在控制台中给了我同样的错误。

感谢您提供的任何帮助! :D

【问题讨论】:

    标签: python twitch


    【解决方案1】:

    很遗憾,Twitch-IO 不支持在没有 ctx 的频道中发送消息。如果这只是为您的聊天主持,这里有一个涉及 websocket-client 的解决方案:

    from websocket import create_connection
    
    irc = "your irc token"
    bot_username = "your bot's username"
    streamer_username = "your username"
    
    def timeout(timeout_username):
        ws = create_connection('wss://irc-ws.chat.twitch.tv')
        ws.send(f"PASS {irc}")
        ws.send(f'NICK {bot_username}')
        ws.send(f"PRIVMSG #{streamer_username} :/timeout {timeout_username} 3s You sent a non-family-friendly word, but we're a family-friendly channel.")
        ws.close()
    

    如果您只是在想要让某人超时的任何时候运行该函数,它应该可以解决问题!这个问题我也有一段时间了,所以我理解这种挫败感

    【讨论】:

      猜你喜欢
      • 2021-06-19
      • 2019-01-20
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多