2017-10-05 3 views
0

を読んでください、私は私が取得エラーメッセージは、私は私を取得しようとしていますはどのように入力変数の配列を通過し、例えば、出力変数

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 

ある

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]) 

を持っていますif文を使用して各コマンドを配列に対してチェックし、出力に応答するプログラム。以降、コードの行6(すなわち、forループ)から

+0

'commandz [i] [0]'は文字列 '' yes ''なので、" y "、" e "、" s "をループします。 'command '[' y '] [0]' –

+0

にアクセスしようとするforループの最初の行stringとyesとhiをマッチさせようとしています。 – trisimix

答えて

0

:あなたのコードで

for comm in commandz: 
    if comm[0] == message.content: 
     await client.send_message(message.channel, comm[1]) 

問題は、あなたが実際に何を望むかときに、(commandz[0][0]に)文字列の文字をループしていることですあなたのネストされたリスト内のリストをループにした(すなわち。["yes","no"]["hi","hi"]commandzに単純である。私はcommandz以内リストなどで変数commを使用して、いないこれらのリスト内の最初のインデックスとして

注意、つまりyeshi私はあなたがそれを使用しようと思っています

関連する問題