The friends system allows your bot to manage friendships, send messages, and track friend status. Friends are represented by the Friend class and pending requests by IncomingPendingFriend and OutgoingPendingFriend.
# Get list of all friendsfriends = client.friendsfor friend in friends: print(f'{friend.display_name} ({friend.id})')# Get number of friendsfriend_count = len(client.friends)
@client.eventasync def event_friend_request(request): # Decline if not on whitelist whitelist = ['allowed-user-id-1', 'allowed-user-id-2'] if request.id not in whitelist: await request.decline() print(f'Declined request from {request.display_name}')
@client.eventasync def event_friend_add(friend): print(f'Added {friend.display_name}, waiting for them to come online...') # Wait for friend to come online await friend.wait_until_online() print(f'{friend.display_name} is now online!') # Send a message await friend.send('Hey! I saw you came online!')
friend = client.get_friend('user-id')if not friend.last_logout: # Fetch from API last_logout = await friend.fetch_last_logout() if last_logout: print(f'Last online: {last_logout}') else: print('Never logged into Fortnite')
friend = client.get_friend('user-id')try: await friend.set_nickname('BestFriend') print(f'Nickname set to: {friend.nickname}')except ValueError as e: print(f'Invalid nickname: {e}')
friend = client.get_friend('user-id')try: await friend.set_note('Met in a random squad fill game') print(f'Note set: {friend.note}')except ValueError as e: print(f'Invalid note: {e}')
import rebootpyfrom rebootpy.errors import PartyError, Forbidden@client.eventasync def event_friend_presence(before, after): friend = after.friend # Check if friend just came online or joined a new party if after.available and after.party and not after.party.private: try: await friend.join_party() print(f'Joined {friend.display_name}\'s party') except PartyError: print('Party not found') except Forbidden: print('Party is private')
friend = client.get_friend('user-id')try: await friend.request_to_join() print(f'Sent join request to {friend.display_name}')except PartyError: print('Already in their party')except FriendOffline: print('Friend is offline')
@client.eventasync def event_friend_presence(before, after): friend = after.friend # Friend came online if before is None or not before.available: if after.available: print(f'{friend.display_name} came online on {after.platform.name}') # Friend went offline elif not after.available: print(f'{friend.display_name} went offline') # Status changed else: if before.status != after.status: print(f'{friend.display_name} status: {after.status}')
VIP_FRIENDS = ['vip-user-id-1', 'vip-user-id-2']@client.eventasync def event_friend_presence(before, after): friend = after.friend # Notify when VIP friend comes online if friend.id in VIP_FRIENDS: if (before is None or not before.available) and after.available: # Send notification (Discord webhook, email, etc.) await send_notification(f'{friend.display_name} is online!')