0
commandz=[["yes","no"],["hi","hi"]]
async def handle_command(message):
print('Noticed: ' + message.content)
if message.content == 'tokenreset'+str(key):
await client.send_message(message.channel, 'code accepted')
i = 0
for i in commandz[i][0]:
comm = commandz[i][0]
if comm == message.content:
await client.send_message(message.channel, commandz[i][1])
该错误消息我得到的是
C:\Users\trisimix>python "c:\Users\trisimix\compsocbot\main.py"
Found saved token in stored.py, use phrase tokenreset1424629785956179 to undo this.
Logged in as[198866998225141760]NOTAKOALAONACOMPUTERINVENEZUELA
--------
Noticed: hi
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\trisimix\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "c:\Users\trisimix\compsocbot\main.py", line 34, in on_message
await handle_command(message)
File "c:\Users\trisimix\compsocbot\main.py", line 42, in handle_command
comm = commandz[i]
TypeError: tuple indices must be integers or slices, not str
我试图让我的程序使用if语句检查数组中的每个命令,然后使用输出进行响应。
'commandz [i] [0]'是字符串'“是”',所以你在循环“y”,“e”和“s”。你尝试访问'for循环的第一行'commandz ['y'] [0]' –
我试图匹配一个字符串与字符串yes和hi,并且返回no或hi如果它的匹配 – trisimix