#🔒 Timed action
37 messages · Page 1 of 1 (latest)
@amber valve
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
so i pretty much going to give a role to somone then in a day remove that role what is the best way to do that considering bot downtimes e.g
i was thinking await asyncio.sleep(int(time)) but not a good idea is it
maybe save the "remove the role" thing in a sort of agenda, with a timestamp on it; then check the agenda every minute or so
because bot downtimes exist, you'd need to persist this in a database.
the trouble with await is that if the bot crashes, it won't continue waiting once it comes back up
yeah i thought that
learn about sqlite; it's not hard
what database would be the best to use
sqlite
ill try that then
best thing about it: it's already installed 🙂
so log the time and check every so often?
exactly
oh thats good
if the bot crashes, no big deal; the agenda is still saved to disk
good docs?: https://docs.python.org/3/library/sqlite3.html
yeah ok cool
unfortunately those docs are nowhere near enough to learn how to use it
you got some?
to help
you need https://www.sqlite.org/docs.html
have a table storing roles given to users, when they should expired, and whether they did. every minute (see discord.ext.tasks), request from the database all entries that should have expired by now but aren't marked as expired (that can be done with just a single SQL query, and if you make sure to have indexes on the right columns it'll even be very fast). If there's any, remove these roles and mark them as expired in the database.
that makes sense do we have some docs for squsal
if you're having trouble understanding SQL (it's a 60-year-old programming language! Of course it's hard to understand), I recommend https://www.postgresql.org/docs/current/tutorial.html -- it's for a different database, but it's pretty similar, and it's nicely written
for the python side see the sqlite3 docs, but for SQL in general, ehh, https://www.sqlitetutorial.net/ isn't bad IMO
ah TIL
ok
so i need help now
File "/home/container/.local/lib/python3.11/site-packages/discord/ext/commands/bot.py", line 935, in _load_from_module_spec
spec.loader.exec_module(lib) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap_external>", line 936, in exec_module
File "<frozen importlib._bootstrap_external>", line 1074, in get_code
File "<frozen importlib._bootstrap_external>", line 1004, in source_to_code
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/container/cogs/genaccess.py", line 54
break
^^^^^
SyntaxError: 'break' outside loop
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/container/.local/lib/python3.11/site-packages/discord/client.py", line 441, in _run_event
await coro(*args, **kwargs)
File "/home/container/main.py", line 22, in on_ready
await client.load_extension(f"cogs.{filename[:-3]}")
File "/home/container/.local/lib/python3.11/site-packages/discord/ext/commands/bot.py", line 1013, in load_extension
await self._load_from_module_spec(spec, name)
File "/home/container/.local/lib/python3.11/site-packages/discord/ext/commands/bot.py", line 938, in _load_from_module_spec
raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.genaccess' raised an error: SyntaxError: 'break' outside loop (genaccess.py, line 54)```
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.