therealmistericraft / MisteriBot

The MisteriBot is a Discord Bot, actually designed only to work on my Server, but I want to change this.
2 stars 0 forks source link

Wrong usage of time.sleep #44

Open therealmistericraft opened 3 years ago

therealmistericraft commented 3 years ago

Description

time.sleep pauses the whole script, not only the command executed by THE person.

Issue Source

Runnig any command that has a sleep function in it, or the welcome message

Current behavior

The whole bot stops working for the slept time

Expected behavior

Only this executement of the command sleeps.

Attachements

See RCCar, Issue 1

Device and software

How to fix?

Run commands with time .sleep as a new threading.Thread

therealmistericraft commented 3 years ago

Changelog: Added precise fix possibility

therealmistericraft commented 3 years ago

Anticipated fix couldn't solve the problem. time.wait() does not exist. Searching for other solution.

joseywoermann commented 3 years ago

asyncio?

joseywoermann commented 3 years ago

@therealmistericraft

joseywoermann commented 3 years ago

Use await asyncio.sleep() and threading. Start a new thread and sleep there.

therealmistericraft commented 3 years ago

Use await asyncio.sleep() and threading. Start a new thread and sleep there.

That is my solution as well, look at "How to fix this?".

joseywoermann commented 3 years ago

Not directly. await asyncio.sleep() is better in asynchronous programming than time.sleep()

therealmistericraft commented 3 years ago

Why? But it works in both cases, so I probably wont change it.

joseywoermann commented 3 years ago

Why? But it works in both cases, so I probably wont change it.

https://discordpy.readthedocs.io/en/latest/faq.html#what-does-blocking-mean

joseywoermann commented 3 years ago

Why? But it works in both cases, so I probably wont change it.

You don't need threading when using await asyncio.sleep(), since when another command is called during the sleeping-time, the sleep()-function will pause until the other command has finished.