前提・実現したいこと
連日すいません。
pythonでdiscordで時間を計測するBOT作成をしています。
例外的なものが発生しているのはわかるのですが、どこでエラーが発生しているかわからないため、教えてください。
エラーメッセージ
C:\Work>python pasttime.py ボイスチャンネルで変化がありました ボイスチャンネルで変化がありました Ignoring exception in on_voice_state_update Traceback (most recent call last): File "C:\Program Files\Python36\lib\site-packages\discord\client.py", line 307, in _run_event yield from getattr(self, event)(*args, **kwargs) File "pasttime.py", line 22, in on_voice_state_update reply_channel = [channel for channel in before.server.channels if channel.name == reply_channel_name][0] IndexError: list index out of range
該当のソースコード
python
1import discord 2import datetime 3 4client = discord.Client() 5pretime_dict = {} 6 7@client.event 8async def on_voice_state_update(before, after): 9 print("ボイスチャンネルで変化がありました") 10 11 if((before.voice.self_mute is not after.voice.self_mute) or (before.voice.self_deaf is not after.voice.self_deaf)): 12 print("ボイスチャンネルでミュート設定の変更がありました") 13 return 14 15 if(before.voice_channel is None): 16 pretime_dict[after.name] = datetime.datetime.now() 17 elif(after.voice_channel is None): 18 duration_time = pretime_dict[before.name] - datetime.datetime.now() 19 duration_time_adjust = int(duration_time.total_seconds()) * -1 20 21 reply_channel_name = "general" 22 reply_channel = [channel for channel in before.server.channels if channel.name == reply_channel_name][0] 23 reply_text = after.name + " が "+ before.voice_channel.name + " から抜けました。 通話時間:" + str(duration_time_adjust) +"秒" 24 25 await client.send_message(reply_channel ,reply_text) 26 27client.run("token")#ボットのトークン 28
補足情報(FW/ツールのバージョンなど)
Windows10 Home x64
pythom 3.6.0