python - (TwitchIO for Python)导入命令时出现无效语法错误
问题描述
我正在尝试在此处的文档中遵循 TwitchIO 教程:https ://twitchio.readthedocs.io/en/latest/quickstart.html
我开始尝试添加 event_message 的第二个代码块,因此我复制了该代码。我只想运行代码,以便开始为 twitch 制作聊天机器人。这是我复制的示例代码,我对其所做的唯一更改是添加了我的令牌和 initial_channels(显然,不包括隐私):
class Bot(commands.Bot):
def __init__(self):
# Initialise our Bot with our access token, prefix and a list of channels to join on boot...
# prefix can be a callable, which returns a list of strings or a string...
# initial_channels can also be a callable which returns a list of strings...
super().__init__(token='ACCESS_TOKEN', prefix='?', initial_channels=['...'])
async def event_ready(self):
# Notify us when everything is ready!
# We are logged in and ready to chat and use commands...
print(f'Logged in as | {self.nick}')
async def event_message(self, message):
# Messages with echo set to True are messages sent by the bot...
# For now we just want to ignore them...
if message.echo:
return
# Print the contents of our message to console...
print(message.content)
# Since we have commands and are overriding the default `event_message`
# We must let the bot know we want to handle and invoke our commands...
await self.handle_commands(message)
@commands.command()
async def hello(self, ctx: commands.Context):
# Here we have a command hello, we can invoke our command with our prefix and command name
# e.g ?hello
# We can also give our commands aliases (different names) to invoke with.
# Send a hello back!
# Sending a reply back to the channel is easy... Below is an example.
await ctx.send(f'Hello {ctx.author.name}!')
bot = Bot()
bot.run()
当我运行此代码时,我收到此错误(更改用户以保持信息私密,哈哈):
Traceback (most recent call last):
File "C:\Users\-USER-\eclipse-workspace\TwitchIO\src\botRD.py", line 13, in <module>
from twitchio.ext import commands
File "C:\Users\-USER-\AppData\Local\Programs\Python\Python36\lib\site-packages\twitchio\__init__.py", line 33, in <module>
from .client import Client
File "C:\Users\-USER-\AppData\Local\Programs\Python\Python36\lib\site-packages\twitchio\client.py", line 36, in <module>
from .http import TwitchHTTP
File "<fstring>", line 1
(await resp.json())
^
SyntaxError: invalid syntax
我不知道从哪里开始这个问题。我尝试进入 twitchio\client.py 但它似乎正在从 .http 导入一些东西,我不确定如何对其进行更改或从那里去哪里。为了以防万一,我尝试重置我的计算机,但这并没有解决错误。这有点超出我的知识范围,所以如果有人能推荐一个好的解决方案,我将不胜感激。如果这很重要,我正在使用 Eclipse IDE 和 Windows 10。
谢谢!
解决方案
TwitchIO 需要 python 3.7+,看起来你正在运行 3.6。我怀疑这是你的问题。
来源:https ://twitchio.readthedocs.io/en/latest/installing.html
推荐阅读
- python - python中的行梯队
- python - 在seaborn分类图中绘制类别意味着
- javascript - 我无法使用 express 在节点 js 中创建虚拟路径前缀(文件系统中实际上不存在该路径)
- powershell - 如何检查powershell中的参数数量?
- reactjs - 如何通过定位文件 REACT 来渲染不同的图像源
- python - import statistics in visual studio code using Python 3.8 cannot find median
- spring-cloud-dataflow - 如何在 Spring Cloud Data Flow 中保存日志文件?
- maven - 如何配置 Intellij 日志级别以调试 Maven 输出
- python-3.x - 执行 conda install notebook 时出现 InvalidArchiveError
- c# - 如何导航到 Blazor 应用程序中的 ASP.NET Core MVC 控制器?