Forums

Discord Bot As Always On Task

I have a Discord bot that I am trying to set up as an always-on task. The bot works fine if I just run the script manually via a Bash console, but it does not seem to work when I try to set it up as an always-on task. It says it is running, but the only line in the log is Task preparing to start; none of the print statements I set up show up, even though I'm using the -u flag in the command (and have flush=True on all my print statements), and it is not doing anything in the server (though it appears to be online).

Again, if I run the script directly, it operates exactly as intended; the issue is only when I try and make it an always-on task.

In case I have messed something up, the command I have is:

python3.9 -u /home/ThePerfectionist/hub/bots/butlerBot.py

UPDATE: After waiting more than an hour for the log to show up, I did discover an error there related to the path of an external file the code had to load. I have fixed that now and the code seems to be running, but I am still not seeing the logs in a timely manner despite my edits to the print statements.

Hi there,

There can be a minor delay in logs appearing sometimes when our servers are busy. What length of delay are you experiencing?

Each of the past few times I've booted it up (including when it was failing and when it was working), the logs took about an hour to appear. I didn't time it exactly, but it's around there.

Could you share some more details with us? Like how often you expect the logs to show up, are they delayed but complete, or are there some logs missing? Do you see any patterns in the slowdowns?

I only notice it at startup, because the bot is used so infrequently that I don't expect regular log messages. But there are several messages that should display as the bot is loading (and indeed the timestamp on the log confirms they are being sent to the print buffer at that time), but they don't appear until much later. As far as I can tell, the logs are complete, just delayed.

The main reason I want to know what's happening is that I read a post on here about always-on tasks, and it said to get the logs to print immediately (rather than waiting for the buffer to fill), you could edit your print statements and/or use the -u flag on the command. I did both of those things, but it didn't make a difference.

Thanks for providing more details, we'll keep an eye on this issue.

it should work for always on tasks. i have mine running on it with no issues...