@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') print(f'Platform: {after.platform.name}') print(f'Status: {after.status}') # Friend went offline elif not after.available: print(f'{friend.display_name} went offline') # Status changed while online else: if before.status != after.status: print(f'{friend.display_name} changed status to: {after.status}')
@client.eventasync def event_friend_presence(before, after): if after.party: if after.party.private: print('Friend is in a private party') else: print('Friend is in a public party') # Can join await after.party.join()
import rebootpyfrom rebootpy.errors import PartyError, Forbidden@client.eventasync def event_friend_presence(before, after): friend = after.friend # Check if friend just came online if (before is None or not before.available) and after.available: if after.party and not after.party.private: try: party = await after.party.join() print(f'Joined {friend.display_name}\'s party') except PartyError: print('Party not found') except Forbidden: print('Party became private')
@client.eventasync def event_friend_presence(before, after): friend = after.friend # Check if gameplay stats exist if after.gameplay_stats: stats = after.gameplay_stats # Check if kills changed if before and before.gameplay_stats: old_kills = before.gameplay_stats.kills new_kills = stats.kills if new_kills > old_kills: print(f'{friend.display_name} got a kill! Total: {new_kills}') # Check players remaining if stats.players_alive <= 10: print(f'{friend.display_name} is in top 10! ({stats.players_alive} left)')
import rebootpy@client.eventasync def event_friend_presence(before, after): if after.available: platform = after.platform if platform == rebootpy.Platform.WINDOWS: print('Friend is on PC') elif platform == rebootpy.Platform.PLAYSTATION: print('Friend is on PlayStation') elif platform == rebootpy.Platform.XBOX: print('Friend is on Xbox') elif platform == rebootpy.Platform.SWITCH: print('Friend is on Nintendo Switch') elif platform == rebootpy.Platform.MOBILE: print('Friend is on Mobile')
@client.eventasync def event_friend_presence(before, after): if after.party_size and after.max_party_size: print(f'Party: {after.party_size}/{after.max_party_size}') if after.party_size == 1: print('Friend is playing alone') elif after.party_size == after.max_party_size: print('Friend\'s party is full')
friend = client.get_friend('user-id')print(f'Waiting for {friend.display_name} to come online...')await friend.wait_until_online()print(f'{friend.display_name} is now online!')# Send a messageawait friend.send('Hey! I saw you came online!')
friend = client.get_friend('user-id')print(f'Waiting for {friend.display_name} to go offline...')await friend.wait_until_offline()print(f'{friend.display_name} went offline')
import asynciofriend = client.get_friend('user-id')try: # Wait up to 5 minutes await asyncio.wait_for( friend.wait_until_online(), timeout=300 ) print('Friend came online!')except asyncio.TimeoutError: print('Friend did not come online within 5 minutes')
@client.eventasync def event_friend_presence(before, after): friend = after.friend # Check if friend is in a duo game if after.playlist and 'duo' in after.playlist.lower(): if after.party and not after.party.private: if after.party.playercount < 2: # Has room await after.party.join() print(f'Joined {friend.display_name} in duos')
VIP_FRIENDS = ['user-id-1', 'user-id-2']@client.eventasync def event_friend_presence(before, after): friend = after.friend if friend.id not in VIP_FRIENDS: return # Friend came online if (before is None or not before.available) and after.available: await send_discord_webhook( f'{friend.display_name} came online on {after.platform.name}' ) # Friend started a match if after.gameplay_stats and (not before or not before.gameplay_stats): await send_discord_webhook( f'{friend.display_name} started a match in {after.playlist}' )
@client.eventasync def event_friend_presence(before, after): friend = after.friend # Check if friend just won (players_alive = 1 usually means victory) if after.gameplay_stats: if after.gameplay_stats.players_alive == 1: # Verify they were in a match before if before and before.gameplay_stats: await friend.send('Congrats on the win!') print(f'{friend.display_name} won a match!')
Presence might be None initially when the bot starts:
friend = client.get_friend('user-id')if friend.last_presence is None: print('Waiting for presence data...') await friend.wait_until_online() # Now presence is available