#目的
discordのボイチャに入ったら、入った時間だけ時間を表示されるbotを作りたい。
#言語
python
#バージョン・ソフト
python3.9.4
vscode
#参考にしたサイト
https://qiita.com/tokkq/items/311aa297175b9cf7f946
#コード
import discord
import datetime
client = discord.Client()
pretime_dict = {}
@client.event
async def on_ready():
print('ログインしました')
@client.event
async def on_voice_state_update(member, before, after):
print("ボイスチャンネルで変化がありました")
if((before.self_mute is not after.self_mute) or (before.voice.self_deaf is not after.voice.self_deaf)):
print("ボイスチャンネルでミュート設定の変更がありました")
return
if(before.voice_channel is None):
pretime_dict[after.name] = datetime.datetime.now()
elif(after.voice_channel is None):
duration_time = pretime_dict[before.name] - datetime.datetime.now()
duration_time_adjust = int(duration_time.total_seconds()) * -1
reply_channel_name = "Study-time" reply_channel = [channel for channel in before.server.channels if channel.name == reply_channel_name][0] reply_text = after.name + " が "+ before.voice_channel.name + " から抜けました。 通話時間:" + str(duration_time_adjust) +"秒" await client.send_message(reply_channel ,reply_text)
client.run("token")
#エラーメッセージ
ログインしました
ボイスチャンネルで変化がありました
Ignoring exception in on_voice_state_update
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\site-packages\discord\client.py", line 343, in
_run_event
await coro(*args, **kwargs)
File "C:\Users\user\Desktop\nob\Virtual_currency_of_the_tool\noob.py", line 15, in
on_voice_state_update
if((before.self_mute is not after.self_mute) or (before.voice.self_deaf is not after.voice.self_deaf)):
AttributeError: 'VoiceState' object has no attribute 'voice'
ボイスチャンネルで変化がありました
Ignoring exception in on_voice_state_update
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\site-packages\discord\client.py", line 343, in
_run_event
await coro(*args, **kwargs)
File "C:\Users\user\Desktop\nob\Virtual_currency_of_the_tool\noob.py", line 15, in
on_voice_state_update
if((before.self_mute is not after.self_mute) or (before.voice.self_deaf is not after.voice.self_deaf)):
AttributeError: 'VoiceState' object has no attribute 'voice'
Exception ignored in: <function _ProactorBasePipeTransport.del at 0x0000014F2B1DADC0>
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\asyncio\proactor_events.py", line 116, in del
File "C:\Program Files\Python39\lib\asyncio\proactor_events.py", line 108, in close
File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 746, in call_soon
File "C:\Program Files\Python39\lib\asyncio\base_events.py", line 510, in _check_closed
RuntimeError: Event loop is closed。
やりたいこと
エラーの解決法を知りたい。
あなたの回答
tips
プレビュー