Helix
Helix

Reputation: 172

How to add a pause between a discord.py bot joining a voice-channel?

I'm making a discord bot with discord.py. The bot is supposed to join the VC and wait lets say 5 minutes, then leave. For testing purposes, this number has been set to 2 seconds. Now the issue is, when the bot joins, the wait function is completley ignored. No matter what I set it to.

I've tried larger numbers but that wont work either.

#The part of the code I'm having trouble with:
try:
    vc = await ctx.guild.get_channel(int(chanid)).connect()
    time.sleep(2)
    await vc.disconnect()
except: 
    print(f"Action Failed: JoinVC.")
#Keep in mind, this is only part of the code.

I expect the bot to attempt to join the channel, and 2 seconds later, leave. I get no error messages when the code is run as is.

Upvotes: 0

Views: 526

Answers (1)

clubby789
clubby789

Reputation: 2723

time.sleep doesn't work well with asyncio, which discord.py is baded on. Try await asyncio.sleep(3) instead.

Upvotes: 1

Related Questions