(Python、Twitch Bot)在实现AutoMod时遇到问题

2024-05-29 02:29:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在为我的流编写一个Twitch调节机器人,我遇到了一个小问题——它的automod部分不起作用。我根本不知道是什么使它不起作用

这是我的密码:

@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


Tags: nameineventsendmessagecontentawaitfamily
1条回答
网友
1楼 · 发布于 2024-05-29 02:29:19

不幸的是,Twitch IO不支持在没有ctx的频道中发送消息。如果这只是为了缓和您的聊天,这里有一个涉及websocket客户端的解决方案:

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()

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

相关问题 更多 >

    热门问题