问题描述
我正在尝试创建一个Python程序来嵌入一个Twitch.tv聊天机器人,当聊天中说了某些事情或事件完成时(新订阅者,关注者等),该机器人将播放预制视频。 我确实有一些问题,但会提及我到目前为止最大的事情。我隐藏了秘密信息。编码器程序= Sublime3 主文件中有时报价会失败,因为主文件中有报价。抱歉。 运行时,我得到的输出是:
python-dotenv Could not parse statement starting at line 1
python-dotenv Could not parse statement starting at line 2
python-dotenv Could not parse statement starting at line 3
python-dotenv Could not parse statement starting at line 4
Traceback (most recent call last):
File "frame1.py",line 149,in <module>
main()
文件“ frame1.py”,主行146 FrameClass(无) init 中的文件“ frame1.py”,第11行 irc_token = os.environ ['TMI_TOKEN'] getitem 中的第675行的文件“ C:\ Program Files \ WindowsApps \ PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0 \ lib \ os.py” 从None提高KeyError(key) KeyError:“ TMI_TOKEN”
进口: gui用wxpython编写 python 3.8.5 python-dotenv twitchio,命令 操作系统
.env
TMI_TOKEN='secret code',CLIENT_ID='secret code',BOT_NICK='Bot name',BOT_PREFIX='!',CHANNEL='Stream channel name'
#frame1.py
导入wx,wx.media 导入操作系统 从twitchio.ext导入命令 从dotenv导入load_dotenv load_dotenv() Class ClassClass(wx.Frame): def init (自己,父母): super(FrameClass,self)。初始化(父项,标题=“超级机器人”,大小=(750,400))
irc_token = os.environ['TMI_TOKEN']
client_id = os.environ['CLIENT_ID']
nick = os.environ['BOT_NICK']
prefic = os.environ['BOT_PREFIX']
initial_channels = os.environ['CHANNEL']
menuBar = wx.MenuBar()
fileMenu = wx.Menu()
connectMenu = wx.Menu()
helpMenu = wx.Menu()
openItem = fileMenu.Append(wx.ID_OPEN,'Open')
saveItem = fileMenu.Append(wx.ID_SAVE,'Save As')
exitItem = fileMenu.Append(wx.ID_EXIT,'EXIT')
helpItem = helpMenu.Append(wx.ID_HELP,'Help!')
menuBar.Append(fileMenu,'&File')
menuBar.Append(connectMenu,'&Connect')
menuBar.Append(helpMenu,'&About')
self.Bind(wx.EVT_MENU,self.Onopen,openItem)
self.Bind(wx.EVT_MENU,self.SaveAs,saveItem)
self.Bind(wx.EVT_MENU,self.Quit,exitItem)
self.Bind(wx.EVT_MENU,self.OnHelp,helpItem)
self.SetMenuBar(menuBar)
self.CreateStatusBar()
self.SetStatusText("Welcome to the new Bot!")
vsplitter = wx.SplitterWindow(self)
left = LeftPanel(vsplitter)
right = RightPanel(vsplitter)
vsplitter.SplitVertically(left,right)
vsplitter.SetMinimumPanesize(200)
bot = chatbot()
self.Show(True)
def Onopen(self,event):
with wx.FileDialog(self,"Open XYZ file",wildcard="XYZ files (*.xyz)|*.xyz",style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog:
if fileDialog.ShowModal() == wx.ID_CANCEL:
return
pathname = fileDialog.GetPath()
try:
with open(pathname,'r') as file:
self.doLoadDataOrWhatever(file)
except IOError:
wx.LogError("Cannot open file '%s'." % newfile)
def SaveAs(self,"Save XYZ file",style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) as fileDialog:
if fileDialog.ShowModal() == wx.ID_CANCEL:
return # the user changed their mind
# save the current contents in the file
pathname = fileDialog.GetPath()
try:
with open(pathname,'w') as file:
self.doSaveData(file)
except IOError:
wx.LogError("Cannot save current data in file '%s'." % pathname)
def Quit(self,e):
self.Close()
def OnHelp(self,e):
"""display an help Dialog"""
wx.MessageBox("This is where future help will be placed. Dont Forget!","Help",wx.OK|wx.ICON_informatION)
LeftPanel类(wx.Panel): def init (自己,父母): wx.Panel。 init (自身,父代=父代)
wx.Button(self,-1,"Test Idle",pos = (10,10))
RightPanel类(wx.Panel): def init (自己,父母): wx.Panel。 init (自身,父代=父代)
self.SetBackgroundColour("grey")
self.testMedia = wx.media.MediaCtrl(self,style=wx.SIMPLE_BORDER,szBackend = wx.media.MEDIABACKEND_WMP10)
self.media = 'C:\\Wiggle_Bot\\Python (Offline)\\JustDoIt.mp4'
self.testMedia.Bind(wx.media.EVT_MEDIA_LOADED,self.play)
self.testMedia.SetVolume(0.5)
if self.testMedia.Load(self.media):
pass
else:
print("Media not found")
self.quit(None)
def play(self,event):
self.testMedia.Play()
chatbot类(commands.Bot): def init (自己): super()。 init (os.environ ['TMI_TOKEN'],os.environ ['CLIENT_ID'],os.environ ['BOT_NICK'],os.environ ['BOT_PREFIX'],os .environ ['CHANNEL'])
# Events don't need decorators when subclassed
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 use a decorator...
@commands.command(name='test')
async def my_command(self,ctx):
await ctx.send(f'Hello {ctx.author.name}!')
def main(): 应用= wx.App() FrameClass(无) App.MainLoop()
main()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)