运行Twitch Bot时发生“从未检索到任务异常”错误

2024-04-18 17:31:05 发布

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

我首先做了一个抽搐机器人 以前,我使用discord.py创建了一个discord机器人

我引用了这个:https://dev.to/ninjabunny9000/let-s-make-a-twitch-bot-with-python-2nd8

这是我的代码:

import os
import twitchio
from twitchio.ext import commands

bot = commands.Bot(
    # set up the bot
    irc_token="my token", #I know I have to change this, but this is for security
    client_id="my client id",
    nick="white_201",
    prefix="!",
    initial_channels="white_201"
)

@bot.event
async def event_ready():
    'Called once when the bot goes online.'
    print("white_201 is online!")
    ws = bot._ws  # this is only needed to send messages within event_ready
    await ws.send_privmsg("white_201", f"/me has landed!")
    #await ws.send_privmsg("espthrobber", f"/ 봇이 당신의 방송을 인식하였습니다.")

@bot.event
async def event_message(ctx):
    print()

@bot.command(name='test')
async def test(ctx):
    await ctx.send('test passed!')

if __name__ == "__main__":
    bot.run()

这是我的错误:

white_201 is online!
Task exception was never retrieved
future: <Task finished name='Task-16' coro=<WebsocketConnection.auth_seq() done, defined at C:\Users\wnrdm\AppData\Local\Programs\Python\Python39\lib\site-packages\twitchio\websocket.py:200> exception=TimeoutError('Request to join the "w" channel has timed out. Make sure the channel exists.')>
Traceback (most recent call last):
  File "C:\Users\wnrdm\AppData\Local\Programs\Python\Python39\lib\asyncio\tasks.py", line 489, in wait_for
    fut.result()
asyncio.exceptions.CancelledError

上述异常是以下异常的直接原因:

Traceback (most recent call last):
  File "C:\Users\wnrdm\AppData\Local\Programs\Python\Python39\lib\site-packages\twitchio\websocket.py", line 280, in _join_channel
    await asyncio.wait_for(fut, timeout=10)
  File "C:\Users\wnrdm\AppData\Local\Programs\Python\Python39\lib\asyncio\tasks.py", line 491, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

在处理上述异常期间,发生了另一个异常:

Traceback (most recent call last):
  File "C:\Users\wnrdm\AppData\Local\Programs\Python\Python39\lib\site-packages\twitchio\websocket.py", line 228, in auth_seq
    await self.join_channels(*channels)
  File "C:\Users\wnrdm\AppData\Local\Programs\Python\Python39\lib\site-packages\twitchio\websocket.py", line 271, in join_channels
    await asyncio.gather(*[self._join_channel(x) for x in channels])
  File "C:\Users\wnrdm\AppData\Local\Programs\Python\Python39\lib\site-packages\twitchio\websocket.py", line 284, in _join_channel
    raise asyncio.TimeoutError(
asyncio.exceptions.TimeoutError: Request to join the "w" channel has timed out. Make sure the channel exists.

Tags: theinpyasyncioliblocalbotchannel