Answer the question
In order to leave comments, you need to log in
Why does the bot go offline?
from discord import FFmpegPCMAudio
from discord.ext import commands
import datetime
import discord
import time
bot = commands.Bot(command_prefix="!")
@bot.command()
async def BigBenStart(ctx):
hour = datetime.datetime.now().hour
channel = ctx.author.voice.channel
while True:
if hour != datetime.datetime.now().hour:
voice = await channel.connect()
source = FFmpegPCMAudio('Big Ben Audio.mp3')
player = voice.play(source)
time.sleep(37)
await ctx.voice_client.disconnect()
hour = datetime.datetime.now().hour
bot.run('ТУТ ТОКЕН')
Answer the question
In order to leave comments, you need to log in
time.sleep(37)
No way. Read how asynchronous programs work.
Roughly speaking, while your handler is executing synchronous code (anything without await), the rest of the program is idle.
So while the bot is sleeping, it does not react to anything at all.
Replace with await asyncio.sleep(37).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question