嗨,我正在使用模块twitchio为twitch创建一个机器人。initial_channels有问题,不知道我做错了什么。下面是我的代码
from twitchio.ext import commands
client_key = 'XXX'
oauth_key = 'XXX'
class bot(commands.Bot):
def __init__(self):
super().__init__(irc_token=oauth_key, client_id=client_key, nick='MrShark', prefix='!',
initial_channels=["recogn1zzze"])
async def event_ready(self):
print(f'Ready | {self.nick}')
async def event_message(self, message):
print(message.content)
await self.handle_commands(message)
@commands.command(name='test')
async def my_command(self, ctx):
await ctx.send(f'Hello {ctx.author.name}!')
bot = bot()
bot.run()
而这里我得到了什么
Task exception was never retrieved
future: <Task finished coro=<WebsocketConnection.join_action() done, defined at C:\Users\recog\AppData\Local\Programs\Python\Python37-32\lib\site-packages\twitchio\websocket.py:543> exception=KeyError('recogn1zzze')>
Traceback (most recent call last):
File "C:\Users\recog\AppData\Local\Programs\Python\Python37-32\lib\site-packages\twitchio\websocket.py", line 558, in join_action
cache = self._channel_cache[channel]['channel']._users
KeyError: 'recogn1zzze'
Task exception was never retrieved
future: <Task finished coro=<WebsocketConnection.join_action() done, defined at C:\Users\recog\AppData\Local\Programs\Python\Python37-32\lib\site-packages\twitchio\websocket.py:543> exception=KeyError('recogn1zzze')>
Traceback (most recent call last):
File "C:\Users\recog\AppData\Local\Programs\Python\Python37-32\lib\site-packages\twitchio\websocket.py", line 558, in join_action
cache = self._channel_cache[channel]['channel']._users
KeyError: 'recogn1zzze'
如何解决这个问题?
nick也应该是recogn1zzze。
nick和initial_channels参数与你的昵称相同,例如如果你的用户是MrShark -> mrshark。
nick='mrshark', prefix='!', initial_channels=['mrshark']