NewSchokr 13 is here. A whole new UI, seven locations, snapshots and more. Read more →

How to update your Discord bot's code on Schokr

Upload new bot code on Schokr and restart with minimal downtime: what to replace, when dependencies reinstall, and how to shut down cleanly.

Updated · 2 min read

To update your bot, upload the changed files with the file manager and restart the server. The bot is offline only for the few seconds it takes to stop, install any new packages and log in again. A single bot connection can't be swapped with zero downtime, but you can keep the gap short and safe.

The quick update

  1. Test the change on your computer first, using a separate test bot token if possible.
  2. Open your server's file manager on Schokr.
  3. Upload the changed files, overwriting the old ones. For many files, upload a zip and extract it over the existing folder.
  4. If you added or upgraded packages, upload the new package.json and lockfile, or requirements.txt.
  5. Restart the server and watch the console until the bot logs in.

Don't overwrite files the bot writes at runtime, such as your SQLite database, .env or log files. Keep them in their own folder (like data/) so a code upload doesn't touch them.

Take a snapshot before risky updates

Before a big change or a database migration, take a backup or snapshot of the server. If the update goes wrong, you can roll back instead of fixing it live. Each server has 3 snapshot slots included.

Use a test bot

Create a second application in the Discord Developer Portal for testing, with its own token. Run it on your computer (or in a second Schokr server) in a private test server. You can break things there without affecting your real users, and you avoid running two copies of the same token.

Shut down cleanly

When the server stops, your bot's process receives a signal. Handling it lets you close the database and disconnect from Discord properly, which avoids corrupted files and makes the bot go offline immediately rather than after a timeout.

discord.js:

async function shutdown(signal) {
  console.log(`Received ${signal}, shutting down...`);
  await client.destroy();
  db?.close();
  process.exit(0);
}

process.on('SIGINT', () => shutdown('SIGINT'));
process.on('SIGTERM', () => shutdown('SIGTERM'));

discord.py handles SIGINT and SIGTERM for you when you start with bot.run(). Put cleanup in an overridden close():

class MyBot(commands.Bot):
    async def close(self):
        await self.db.close()
        await super().close()

Reload without restarting (discord.py)

discord.py can reload a cog without restarting the bot, so the bot stays online:

@bot.command()
@commands.is_owner()
async def reload(ctx, extension: str):
    await bot.reload_extension(f"cogs.{extension}")
    await ctx.send(f"Reloaded {extension}")

Upload the changed cog, then run !reload fun. Changes to the main file or to packages still need a full restart. discord.js can do something similar by clearing the require cache for a command file, but a restart is simpler and safer.

Restart on a schedule

If your bot slowly uses more memory over days, a scheduled restart can help while you look for the cause. Use your server's Schedules section to restart at a quiet time, such as overnight. See reducing bot memory usage.

Slash command changes

If you changed command names, options or descriptions, they need to be re-registered with Discord. See discord.js slash commands or discord.py slash commands.

Tip: for large uploads, you can also use an SFTP client like FileZilla. See how to connect with SFTP.