Skip to main content

Your First Bot

This guide will walk you through creating a simple Fortnite bot using rebootpy. By the end, you’ll have a bot that automatically accepts friend requests and responds to commands.
Before starting, make sure you have installed rebootpy on your system.

Basic Bot Example

1

Create your bot file

Create a new Python file (e.g., bot.py) and add the following code:
import rebootpy
from rebootpy.ext import commands

bot = commands.Bot(
    command_prefix='!',
    auth=rebootpy.AuthorizationCodeAuth()
)

@bot.event
async def event_ready():
    print(f'Bot ready as {bot.user.display_name} ({bot.user.id})')

@bot.event
async def event_friend_request(request):
    await request.accept()

@bot.command()
async def hello(ctx):
    await ctx.send('Hello!')

bot.run()
This creates a basic bot with:
  • Authorization code authentication
  • Auto-accept friend requests
  • A !hello command that responds with “Hello!”
2

Obtain an authorization code

To authenticate your bot, you need to get an authorization code:
  1. Log into the Epic Games account you want to use for your bot: Get Authorization Code
  2. Copy the value of the authorizationCode field from the JSON response
Authorization codes are single-use and expire quickly. For persistent bots, consider using DeviceAuth or AdvancedAuth instead.
3

Run your bot

Execute your bot script:
python bot.py
When prompted, paste the authorization code you obtained in the previous step.
4

Test your bot

Once your bot is running:
  • Send a friend request to your bot account from another Epic Games account
  • The bot will automatically accept the request
  • Send the message !hello to your bot
  • The bot should respond with “Hello!”

Advanced Bot with Device Auth

For a production bot that persists authentication across restarts, use AdvancedAuth with device authentication:
import rebootpy
import json
import os

from rebootpy.ext import commands

filename = 'device_auths.json'

def get_device_auth_details():
    if os.path.isfile(filename):
        with open(filename, 'r') as fp:
            return json.load(fp)
    return {}

def store_device_auth_details(details):
    with open(filename, 'w') as fp:
        json.dump(details, fp)

device_auth_details = get_device_auth_details()
bot = commands.Bot(
    command_prefix='!',
    auth=rebootpy.AdvancedAuth(
        prompt_device_code=True,
        open_link_in_browser=True,
        **device_auth_details
    )
)

@bot.event
async def event_device_auth_generate(details):
    store_device_auth_details(details)

@bot.event
async def event_ready():
    print(f'Bot ready as {bot.user.display_name} ({bot.user.id}).')

@bot.event
async def event_friend_request(request):
    await request.accept()

@bot.command()
async def hello(ctx):
    await ctx.send('Hello!')

bot.run()

How This Works

1

First Run

On the first run, the bot will:
  • Open a browser window for device code authentication
  • Generate device authentication credentials
  • Save them to device_auths.json
2

Subsequent Runs

On future runs:
  • The bot loads credentials from device_auths.json
  • No manual authentication required
  • The bot starts automatically
Keep your device_auths.json file secure and private. It contains credentials that can be used to access your Epic Games account.

Understanding the Code

Bot Initialization

bot = commands.Bot(
    command_prefix='!',
    auth=rebootpy.AuthorizationCodeAuth()
)
  • command_prefix: The prefix for bot commands (e.g., !hello, !help)
  • auth: The authentication method to use

Events

Events are triggered by specific actions:
@bot.event
async def event_ready():
    print(f'Bot ready as {bot.user.display_name} ({bot.user.id})')
The event_ready event fires when the bot successfully connects and is ready to operate.
@bot.event
async def event_friend_request(request):
    await request.accept()
The event_friend_request event fires when someone sends a friend request. This example automatically accepts all requests.

Commands

@bot.command()
async def hello(ctx):
    await ctx.send('Hello!')
Commands are triggered by users with the specified prefix. The ctx parameter provides context like the sender and conversation.

Next Steps

Now that you have a working bot, explore more features:

Authentication Methods

Learn about different authentication options

Events

Discover all available events

Commands

Build more complex command handlers

Party Management

Manage parties and party members

Common Issues

Authorization Code Expired

Authorization codes are single-use and expire quickly. If you get an authentication error:
  • Generate a new authorization code
  • Consider using AdvancedAuth for persistent authentication

Bot Not Responding to Commands

Ensure:
  • You’re using the correct command prefix (default: !)
  • You’re sending commands as friend messages to the bot
  • The bot has successfully started (check for “Bot ready” message)

Import Errors

If you encounter import errors:
  • Verify rebootpy is installed: pip list | grep rebootpy
  • Reinstall if necessary: pip install -U rebootpy