Answer the question
In order to leave comments, you need to log in
How to count the time spent in the voice channel?
Hi guys, using this function "on_voice_state_update" I want to count the time spent in the voice channel. The person entered, and the data was recorded in the database, and well, so that all this would be displayed in the user profile, but I will do this myself.
@commands.command()
async def user (self, ctx, user: discord.Member = None):
user = ctx.author if (user is None) else user
statuses = {
"online": "<:online:781849066891247617> Онлайн",
"idle": "<:idle:781849067294031912> Не активен",
"dnd": "<:dnd:781849067067932672> Не беспокоить",
"offline": "<:offline:781849067029528586> Не в cети"
}
j_month = user.joined_at.strftime('%b')
j_day = user.joined_at.strftime('%#d')
j_year = user.joined_at.strftime('%Y')
j_time = user.joined_at.strftime('%X')
c_month = user.created_at.strftime('%b')
c_day = user.created_at.strftime('%#d')
c_year = user.created_at.strftime('%Y')
c_time = user.created_at.strftime('%X')
status = statuses[str(user.status)]
Answer the question
In order to leave comments, you need to log in
@bot.event
async def on_voice_state_update(member, before, after):
# Если пользователь зашел в голосовой канал
if after.channel and after.channel.type == discord.ChannelType.voice:
joined_voice_channel = time.time()
# сохраняем в БД
# если вышел из голосового
if not after.channel and before.channel.type == discord.ChannelType.voice:
leave_voice_channel = time.time()
# достаем из БД joined_voice_channel и вычитаем его из leave_voice_channel
print('Время в голосовом канале:', leave_voice_channel-joined_voice_channel, 'секунд')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question