App hosting

Discord bot with Python

Build a bot with discord.py and keep it online around the clock on RHQ App Hosting.

This guide starts from zero: you create the bot in Discord, write a small bot with a !ping command and start it on your RHQ Python server.

  1. Create the application in Discord

    Go to the Discord Developer Portal, click New Application, give it a name and confirm.

  2. Get the bot token

    Open the Bot tab and click Reset Token. Copy the token and keep it to yourself.

    On the same page, under Privileged Gateway Intents, turn on Message Content Intent. Prefix commands need it.

  3. Invite the bot to your Discord server

    Open OAuth2 → URL Generator, tick the bot scope and the Send Messages and Read Message History permissions. Open the generated link and pick your server.

  4. Prepare the project

    On your computer, create a folder with three files.

    requirements.txt
    text
    discord.py>=2.4
    python-dotenv>=1.0
    main.py
    python
    import os
    import discord
    from discord.ext import commands
    from dotenv import load_dotenv
     
    load_dotenv()
     
    intents = discord.Intents.default()
    intents.message_content = True
    bot = commands.Bot(command_prefix="!", intents=intents)
     
    @bot.event
    async def on_ready():
        print(f"Logged in as {bot.user}")
     
    @bot.command()
    async def ping(ctx):
        await ctx.reply("Pong!")
     
    bot.run(os.environ["DISCORD_TOKEN"])
    .env
    ini
    DISCORD_TOKEN=paste_your_token_here
  5. Upload the files to the panel

    In the RHQ panel open the Files tab and upload requirements.txt, main.py and .env.

  6. Set the main file and start

    In the Startup tab set the main file to main.py, then click Start. Libraries install on the first start. When Console shows Logged in as ..., type !ping in Discord.

Troubleshooting

The bot is online but does not answer !ping

Check that Message Content Intent is on in the Developer Portal and that the code has intents.message_content = True.

The console shows "ModuleNotFoundError: No module named 'discord'"

requirements.txt is missing or has a different name. Upload it to the main folder and restart the server so the libraries install.