### Extension example with extension_setup Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/extensions.rst Defines a simple command and an extension_setup entry point that adds the command to the bot when the extension is loaded. The setup function must be a plain Python function (not a coroutine) and takes a single parameter, the Bot instance. ```python3 from fortnitepy.ext import commands @commands.command() async def hello(ctx): await ctx.send('Hello {0.display_name}.'.format(ctx.author)) def extension_setup(bot): bot.add_command(hello) ``` -------------------------------- ### Install fortnitepy with pip on Windows and Linux Source: https://github.com/terbau/fortnitepy/blob/master/README.md Install the library using pip. The Windows command uses 'py -3' while the Linux command uses 'python3'. ```bash # windows py -3 -m pip install -U fortnitepy # linux python3 -m pip install -U fortnitepy ``` -------------------------------- ### Install fortnitepy on Windows Source: https://github.com/terbau/fortnitepy/blob/master/docs/intro.rst Install fortnitepy using Python 3.5 or higher on Windows. Run this command in a terminal. ```sh py -3 -m pip install fortnitepy ``` -------------------------------- ### Install fortnitepy on Linux Source: https://github.com/terbau/fortnitepy/blob/master/docs/intro.rst Install fortnitepy using Python 3.5 or higher on Linux. Run this command in a terminal. ```sh python3 -m pip install fortnitepy ``` -------------------------------- ### Positional input and output examples Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Shows user input and corresponding output for the positional parameter command, including quoting behavior. ```none $test hello ``` ```none hello ``` ```none $test "hello world" ``` ```none hello world ``` ```none $test hello world ``` ```none hello ``` -------------------------------- ### Keyword-only argument input and output examples Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Shows user input and output for the keyword-only argument command, including quoting behavior. ```none $test hello world ``` ```none hello world ``` ```none $test "hello world" ``` ```none "hello world" ``` -------------------------------- ### event_ready() Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Called when the client has been successfully established and connected to all services. Not called when the client starts in Client.close(). ```APIDOC ## event_ready() ### Description Called when the client has been successfully established and connected to all services. Not called when the client starts in Client.close(). ### Method Event ### Parameters None ### Notes - This event is not called when the client starts in Client.close(). ``` -------------------------------- ### Variable arguments input and output examples Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Shows user input and output for the variable arguments command, including quoting and no-argument cases. ```none $test hello there friend ``` ```none 3 arguments: hello, there, friend ``` ```none $test hello there "my friend" ``` ```none 3 arguments: hello, there, my friend ``` ```none $test ``` ```none 0 arguments: ``` -------------------------------- ### User invocation of basic command Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Example user input that invokes the 'foo' command with argument 'abc'. ```none $foo abc ``` -------------------------------- ### Basic fortnitepy client example Source: https://github.com/terbau/fortnitepy/blob/master/docs/intro.rst A basic fortnitepy client that uses AdvancedAuth, stores device auth details in a JSON file, and handles friend requests and messages. Requires an authorization code on first launch. ```python3 import fortnitepy import json import os email = 'email@email.com' password = 'password1' filename = 'device_auths.json' class MyClient(fortnitepy.Client): def __init__(self): device_auth_details = self.get_device_auth_details().get(email, {}) super().__init__( auth=fortnitepy.AdvancedAuth( email=email, password=password, prompt_authorization_code=True, prompt_code_if_invalid=True, delete_existing_device_auths=True, **device_auth_details ) ) def get_device_auth_details(self): if os.path.isfile(filename): with open(filename, 'r') as fp: return json.load(fp) return {} def store_device_auth_details(self, email, details): existing = self.get_device_auth_details() existing[email] = details with open(filename, 'w') as fp: json.dump(existing, fp) async def event_device_auth_generate(self, details, email): self.store_device_auth_details(email, details) async def event_ready(self): print('----------------') print('Client ready as') print(self.user.display_name) print(self.user.id) print('----------------') async def event_friend_request(self, request): await request.accept() async def event_friend_message(self, message): print('Received message from {0.author.display_name} | Content: "{0.content}"'.format(message)) await message.reply('Thanks for your message!') client = MyClient() client.run() ``` -------------------------------- ### event_before_start() Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Called and waited for before the client starts. The client will wait until the event handlers for this event are finished processing before actually closing. Not called when the client starts in Client.restart(). ```APIDOC ## event_before_start() ### Description Called and waited for before the client starts. The client will wait until the event handlers for this event are finished processing before actually closing. This makes it so you are able to do heavy and/or time consuming operations before the client fully logs out. This unfortunately also means that this event is not compatible with Client.wait_for(). ### Method Event ### Parameters None ### Notes - This event is not called when the client starts in Client.restart(). - This event behaves differently from the other events. The client will wait until the event handlers for this event are finished processing before actually closing. ``` -------------------------------- ### Get commands from a cog Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/cogs.rst Retrieves a list of commands from a cog using Cog.get_commands(). The example shows getting the 'Greetings' cog and printing the command names. ```python >>> cog = bot.get_cog('Greetings') >>> commands = cog.get_commands() >>> print([c.name for c in commands]) ``` -------------------------------- ### Example output of Greedy converter Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Shows the expected console output when two users are in the same party, which the source notes will essentially never happen. ```text Ninja, Tfue just got slapped for good reason! ``` -------------------------------- ### Greedy converter usage in a command Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst Shows how to use the Greedy converter to consume multiple arguments until parsing fails. In this example, invoking the command with '1 2 3 4 5 6 hello' passes numbers as [1, 2, 3, 4, 5, 6] and reason as 'hello'. ```python3 @commands.command() async def test(ctx, numbers: Greedy[int], reason: str): await ctx.send("numbers: {}, reason: {}".format(numbers, reason)) ``` -------------------------------- ### event_party_update Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Event called when ClientUser's partymeta is updated. An example of when this is called is when a new custom key has been set. ```APIDOC ## event_party_update ### Description Event called when ClientUser's partymeta is updated. An example of when this is called is when a new custom key has been set. ### Parameters - **party** (Party) - Required - The party that was updated. ``` -------------------------------- ### event_friend_add(friend) Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Called when a friend has been added. Called regardless of the direction, meaning it will get called even if the client were to be the one to accept the user. ```APIDOC ## event_friend_add(friend) ### Description Called when a friend has been added. Called regardless of the direction, meaning it will get called even if the client were to be the one to accept the user. ### Method Event ### Parameters - **friend** (Friend) - Required - Friend that has been added. ``` -------------------------------- ### event_party_member_update Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Event called when the meta of a member of ClientUser's party is updated. An example of when this might get called is when a member changes outfit. ```APIDOC ## event_party_member_update ### Description Event called when the meta of a member of ClientUser's party is updated. An example of when this might get called is when a member changes outfit. ### Parameters - **member** (PartyMember) - Required - The member whos meta was updated. ``` -------------------------------- ### Basic usage of fortnitepy with commands extension Source: https://github.com/terbau/fortnitepy/blob/master/README.md Initializes the fortnitepy client with email and password credentials, loading device auth details from a JSON file if present. Requires the fortnitepy.ext.commands extension and a device_auths.json file for device authentication. ```python import fortnitepy import json import os from fortnitepy.ext import commands email = 'email@email.com' password = 'password1' 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 {} ``` -------------------------------- ### fortnitepy.ext.commands.HelpCommand Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst The HelpCommand class is the base class for implementing help commands. ```APIDOC ## fortnitepy.ext.commands.HelpCommand ### Description The HelpCommand class is the base class for implementing help commands. ### Members Refer to the official documentation for the full list of members. ``` -------------------------------- ### Two equivalent ways to register a command Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Shows both registration methods: using the Bot.command decorator and using the command decorator followed by Bot.add_command. Both are equivalent. ```python3 from fortnitepy.ext import commands bot = commands.Bot(command_prefix='$') @bot.command() async def test(ctx): pass # or: @commands.command() async def test(ctx): pass bot.add_command(test) ``` -------------------------------- ### Initialize client with manual net_cl Source: https://github.com/terbau/fortnitepy/blob/master/docs/faq.rst Pass the net_cl keyword when initializing the client to fix the 'Incompatible net_cl' error. The net_cl is a seven-digit number found in Fortnite logs. ```python # pass the netcl to with the net_cl keyword when initializing the client. client = fortnitepy.Client( auth=fortnitepy.Auth, // Here goes an authentication method like fortnitepy.AdvancedAuth or fortnitepy.EmailAndPasswordAuth net_cl='7605985' ) ``` -------------------------------- ### fortnitepy.ext.commands.FortniteHelpCommand Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst The FortniteHelpCommand class is a default implementation of HelpCommand tailored for Fortnite. ```APIDOC ## fortnitepy.ext.commands.FortniteHelpCommand ### Description The FortniteHelpCommand class is a default implementation of HelpCommand tailored for Fortnite. ### Members Refer to the official documentation for the full list of members, excluding send_bot_help, send_cog_help, send_group_help, send_command_help, and prepare_help_command. ``` -------------------------------- ### event_friend_remove(friend) Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Called when a friend has been removed from the friendlist. Called regardless of the direction, meaning it will get called even if the client were to be the one to remove the friend. ```APIDOC ## event_friend_remove(friend) ### Description Called when a friend has been removed from the friendlist. Called regardless of the direction, meaning it will get called even if the client were to be the one to remove the friend. ### Method Event ### Parameters - **friend** (Friend) - Required - Friend that was removed. ``` -------------------------------- ### Equivalent converter usage with and without instantiation Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Shows that a converter can be used either as a class or as an instance; both are equivalent. ```python @bot.command() async def slap(ctx, *, reason: Slapper): await ctx.send(reason) # is the same as... @bot.command() async def slap(ctx, *, reason: Slapper()): await ctx.send(reason) ``` -------------------------------- ### Define a basic command with @bot.command() Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Defines a command that takes a positional argument and sends it back. Invoked with the prefix '$' as '$foo abc'. ```python3 @bot.command() async def foo(ctx, arg): await ctx.send(arg) ``` -------------------------------- ### BasicClient Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst The BasicClient class is a client for interacting with Fortnite. It provides core functionality for connecting and managing sessions. ```APIDOC ## BasicClient ### Description The BasicClient class is a client for interacting with Fortnite. It provides core functionality for connecting and managing sessions. ### Methods Refer to the source documentation for the full list of members. The class is defined with `:members:` directive, indicating all public methods and attributes are documented. ``` -------------------------------- ### Define a Greetings cog with a command and event listener Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/cogs.rst Shows a cog subclassing commands.Cog with an event handler for party member joins and a hello command. The event handler must be marked with @commands.Cog.event() and commands must take a self parameter. ```python3 class Greetings(commands.Cog): def __init__(self, bot): self.bot = bot self._last_member = None @commands.Cog.event() async def event_party_member_join(self, member): party = member.party await party.send('Welcome {0.display_name}.'.format(member)) @commands.command() async def hello(self, ctx, *, member: fortnitepy.Member = None): """Says hello""" member = member or ctx.author if self._last_member is None or self._last_member.id != member.id: await ctx.send('Hello {0.display_name}~'.format(member)) else: await ctx.send('Hello {0.display_name}... This feels familiar.'.format(member)) self._last_member = member ``` -------------------------------- ### Authentication Classes Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Authentication methods for logging into Fortnite. Includes EmailAndPasswordAuth, ExchangeCodeAuth, AuthorizationCodeAuth, DeviceAuth, RefreshTokenAuth, and AdvancedAuth. ```APIDOC ## Authentication Classes ### Description These classes handle different authentication methods for the fortnitepy client. As of v1.4.0, you must specify which authentication method to use for login. The preferred method is DeviceAuth, set up via AdvancedAuth. ### Classes - **EmailAndPasswordAuth** - Uses email and password for authentication. May require captcha. - **ExchangeCodeAuth** - Uses an exchange code for authentication. - **AuthorizationCodeAuth** - Uses an authorization code for authentication. - **DeviceAuth** - Uses device authentication, preferred method. - **RefreshTokenAuth** - Uses a refresh token for authentication. - **AdvancedAuth** - Handles setup and management of authentication, including file storage for DeviceAuth. ### Usage Refer to the example at https://github.com/Terbau/fortnitepy/blob/master/examples/basic_client.py for setting up AdvancedAuth with DeviceAuth. ``` -------------------------------- ### fortnitepy.ext.commands.Command Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst The Command class represents a single command that can be invoked by users. It includes the special method __call__. ```APIDOC ## fortnitepy.ext.commands.Command ### Description The Command class represents a single command that can be invoked by users. It includes the special method __call__. ### Members Refer to the official documentation for the full list of members and special members. ``` -------------------------------- ### Client Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst The Client class is the main client for fortnitepy, inheriting from BasicClient and providing additional features. ```APIDOC ## Client ### Description The Client class is the main client for fortnitepy, inheriting from BasicClient and providing additional features. ### Methods Refer to the source documentation for the full list of members, including inherited members. ``` -------------------------------- ### Extension cleanup with cog_teardown Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/extensions.rst Shows the optional cog_teardown entry point, which is called when the extension is unloaded, allowing cleanup. Both functions take the bot as a parameter. ```python3 def extension_setup(bot): print('I am being loaded!') def cog_teardown(bot): print('I am being unloaded!') ``` -------------------------------- ### Stats Reference - Default Duos Gamemode (defaultduo) Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Describes the structure of stats data for the default duos gamemode. ```APIDOC ## Stats Reference - Default Duos Gamemode (defaultduo) ### Description Structure of stats data for the default duos gamemode. ### Fields - **wins** (int) - Number of wins. - **placetop5** (int) - Number of top 5 placements. - **placetop12** (int) - Number of top 12 placements. - **kills** (int) - Number of kills. - **score** (int) - Score. - **playersoutlives** (int) - Players outlived. - **minutesplayed** (int) - Minutes played. - **matchesplayed** (int) - Matches played. - **lastmodified** (datetime.datetime) - Last modified timestamp. ``` -------------------------------- ### Basic converter with int annotation Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Converts command arguments to integers using function annotations. The command 'add' takes two integers and sends their sum. ```python @bot.command() async def add(ctx, a: int, b: int): await ctx.send(a + b) ``` -------------------------------- ### fortnitepy.ext.commands.Bot Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst The Bot class for the command extension module. It provides the main interface for creating and managing commands. ```APIDOC ## fortnitepy.ext.commands.Bot ### Description The Bot class for the command extension module. It provides the main interface for creating and managing commands. ### Members Refer to the official documentation for the full list of members and inherited members. ``` -------------------------------- ### Set a client status on initialization Source: https://github.com/terbau/fortnitepy/blob/master/docs/faq.rst Pass a status message to the Client constructor to set the initial status. This overrides all future status messages, including the standard 'Battle Royale Lobby {party size} / {party max size}'. Use Client.send_presence for a one-time status. ```python client = fortnitepy.Client( auth=fortnitepy.Auth, // Here goes an authentication method like fortnitepy.AdvancedAuth or fortnitepy.EmailAndPasswordAuth status="This is my status" ) ``` -------------------------------- ### Stats Reference - Default Solos Gamemode (defaultsolo) Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Describes the structure of stats data for the default solos gamemode. ```APIDOC ## Stats Reference - Default Solos Gamemode (defaultsolo) ### Description Structure of stats data for the default solos gamemode. ### Fields - **wins** (int) - Number of wins. - **placetop10** (int) - Number of top 10 placements. - **placetop25** (int) - Number of top 25 placements. - **kills** (int) - Number of kills. - **score** (int) - Score. - **playersoutlives** (int) - Players outlived. - **minutesplayed** (int) - Minutes played. - **matchesplayed** (int) - Matches played. - **lastmodified** (datetime.datetime) - Last modified timestamp. ``` -------------------------------- ### fortnitepy.ext.commands.GroupMixin Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst The GroupMixin class provides functionality for managing subcommands within a group. ```APIDOC ## fortnitepy.ext.commands.GroupMixin ### Description The GroupMixin class provides functionality for managing subcommands within a group. ### Members Refer to the official documentation for the full list of members. ``` -------------------------------- ### Stats Reference - Default Squads Gamemode (defaultsquad) Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Describes the structure of stats data for the default squads gamemode. ```APIDOC ## Stats Reference - Default Squads Gamemode (defaultsquad) ### Description Structure of stats data for the default squads gamemode. ### Fields - **wins** (int) - Number of wins. - **placetop3** (int) - Number of top 3 placements. - **placetop6** (int) - Number of top 6 placements. - **kills** (int) - Number of kills. - **score** (int) - Score. - **playersoutlives** (int) - Players outlived. - **minutesplayed** (int) - Minutes played. - **matchesplayed** (int) - Matches played. - **lastmodified** (datetime.datetime) - Last modified timestamp. ``` -------------------------------- ### command() Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst A decorator that transforms a function into a Command. This is part of the command extension module's public API. ```APIDOC ## command() ### Description A decorator that transforms a function into a Command. This is part of the command extension module's public API. ### Usage Refer to the official documentation for the full signature and parameters. ``` -------------------------------- ### fortnitepy.ext.commands.Group Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst The Group class represents a command that can contain subcommands. It inherits from Command and GroupMixin. ```APIDOC ## fortnitepy.ext.commands.Group ### Description The Group class represents a command that can contain subcommands. It inherits from Command and GroupMixin. ### Members Refer to the official documentation for the full list of members and inherited members. ``` -------------------------------- ### Utility Functions Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Utility functions provided by the package for managing multiple clients. ```APIDOC ## Utility Functions ### Description Utility functions provided by the package for managing multiple clients. ### Functions - **run_multiple** - Runs multiple clients concurrently. - **start_multiple** - Starts multiple clients concurrently. - **close_multiple** - Closes multiple clients concurrently. ``` -------------------------------- ### event_device_auth_generate(details, email) Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Called whenever new device authentication details are generated. ```APIDOC ## event_device_auth_generate(details, email) ### Description Called whenever new device authentication details are generated. ### Method Event ### Parameters - **details** (dict) - Required - A dictionary containing the keys device_id, account_id, and secret. - **email** (str) - Required - Email of the account that just generated new device auth details. ``` -------------------------------- ### Context Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst The Context class represents the context in which a command is being invoked. ```APIDOC ## Context ### Description The Context class represents the context in which a command is being invoked. ### Class `fortnitepy.ext.commands.Context` ### Members Refer to the autoclass documentation for all members, including inherited members. ``` -------------------------------- ### event_xmpp_session_establish() Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Called whenever an XMPP session has been established. This can be called multiple times. ```APIDOC ## event_xmpp_session_establish() ### Description Called whenever an XMPP session has been established. This can be called multiple times. ### Method Event ### Parameters None ``` -------------------------------- ### fortnitepy.ext.commands.CogMeta Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst The CogMeta class is the metaclass for Cog, providing additional functionality for cog creation. ```APIDOC ## fortnitepy.ext.commands.CogMeta ### Description The CogMeta class is the metaclass for Cog, providing additional functionality for cog creation. ### Members Refer to the official documentation for the full list of members. ``` -------------------------------- ### Exceptions Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst Exception classes raised by the commands extension. ```APIDOC ## Exceptions ### Description Exception classes raised by the commands extension. ### Exception Classes - `fortnitepy.ext.commands.CommandError` - `fortnitepy.ext.commands.ConversionError` - `fortnitepy.ext.commands.MissingRequiredArgument` - `fortnitepy.ext.commands.ArgumentParsingError` - `fortnitepy.ext.commands.UnexpectedQuoteError` - `fortnitepy.ext.commands.InvalidEndOfQuotedStringError` - `fortnitepy.ext.commands.ExpectedClosingQuoteError` - `fortnitepy.ext.commands.BadArgument` - `fortnitepy.ext.commands.BadUnionArgument` - `fortnitepy.ext.commands.PrivateMessageOnly` - `fortnitepy.ext.commands.PartyMessageOnly` - `fortnitepy.ext.commands.CheckFailure` - `fortnitepy.ext.commands.CheckAnyFailure` - `fortnitepy.ext.commands.CommandNotFound` - `fortnitepy.ext.commands.DisabledCommand` - `fortnitepy.ext.commands.CommandInvokeError` - `fortnitepy.ext.commands.TooManyArguments` - `fortnitepy.ext.commands.UserInputError` - `fortnitepy.ext.commands.CommandOnCooldown` - `fortnitepy.ext.commands.MaxConcurrencyReached` - `fortnitepy.ext.commands.NotOwner` - `fortnitepy.ext.commands.ExtensionError` - `fortnitepy.ext.commands.ExtensionAlreadyLoaded` - `fortnitepy.ext.commands.ExtensionNotLoaded` - `fortnitepy.ext.commands.ExtensionMissingEntryPoint` - `fortnitepy.ext.commands.ExtensionFailed` - `fortnitepy.ext.commands.ExtensionNotFound` ``` -------------------------------- ### Cog.walk_commands Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/cogs.rst Generator that yields all commands and subcommands in the cog. ```APIDOC ## Cog.walk_commands ### Description Generator that yields all commands and subcommands in the cog. ### Method Cog.walk_commands ### Parameters None ### Returns - **generator** - Yields Command objects. ### Example ```python print([c.qualified_name for c in cog.walk_commands()]) ``` ``` -------------------------------- ### fortnitepy.ext.commands.Cog Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst The Cog class is a base class for creating cogs, which are collections of commands and event listeners. ```APIDOC ## fortnitepy.ext.commands.Cog ### Description The Cog class is a base class for creating cogs, which are collections of commands and event listeners. ### Members Refer to the official documentation for the full list of members. ``` -------------------------------- ### List event handlers Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/cogs.rst Uses Cog.get_listeners() to retrieve event handlers as tuples of listener name and function, printing each pair. ```python >>> for name, func in cog.get_listeners(): ... print(name, '->', func) ``` -------------------------------- ### Walk through subcommands Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/cogs.rst Uses Cog.walk_commands() to iterate over all commands including subcommands, printing their qualified names. ```python >>> print([c.qualified_name for c in cog.walk_commands()]) ``` -------------------------------- ### Stats Reference - Default Trios Gamemode (trios) Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Describes the structure of stats data for the default trios gamemode. ```APIDOC ## Stats Reference - Default Trios Gamemode (trios) ### Description Structure of stats data for the default trios gamemode. ### Fields - **wins** (int) - Number of wins. - **kills** (int) - Number of kills. - **score** (int) - Score. - **playersoutlives** (int) - Players outlived. - **minutesplayed** (int) - Minutes played. - **matchesplayed** (int) - Matches played. - **lastmodified** (datetime.datetime) - Last modified timestamp. ``` -------------------------------- ### Cog.get_commands Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/cogs.rst Returns a list of commands registered in the cog. ```APIDOC ## Cog.get_commands ### Description Returns a list of commands registered in the cog. ### Method Cog.get_commands ### Parameters None ### Returns - **list** - A list of Command objects. ### Example ```python cog = bot.get_cog('Greetings') commands = cog.get_commands() print([c.name for c in commands]) ``` ``` -------------------------------- ### Multiple positional parameters command Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Defines a command with two positional parameters and formats them into a message. ```python3 @bot.command() async def test(ctx, arg1, arg2): await ctx.send('You passed {} and {}'.format(arg1, arg2)) ``` -------------------------------- ### Register a cog with bot.add_cog Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/cogs.rst Registers the Greetings cog with the bot, automatically adding all its commands and listeners. ```python3 bot.add_cog(Greetings(bot)) ``` -------------------------------- ### Keyword-only argument command Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Defines a command with a keyword-only argument that captures the rest of the input as a single string. ```python3 @bot.command() async def test(ctx, *, arg): await ctx.send(arg) ``` -------------------------------- ### Paginator Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst The Paginator class is used to paginate text output in commands. ```APIDOC ## Paginator ### Description The Paginator class is used to paginate text output in commands. ### Class `fortnitepy.ext.commands.Paginator` ### Members Refer to the autoclass documentation for all members. ``` -------------------------------- ### event_restart() Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Called when the client has successfully restarted. ```APIDOC ## event_restart() ### Description Called when the client has successfully restarted. ### Method Event ### Parameters None ``` -------------------------------- ### group() Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst A decorator that transforms a function into a Group. This is part of the command extension module's public API. ```APIDOC ## group() ### Description A decorator that transforms a function into a Group. This is part of the command extension module's public API. ### Usage Refer to the official documentation for the full signature and parameters. ``` -------------------------------- ### Variable arguments command Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Defines a command that accepts a variable number of positional arguments using *args. ```python3 @bot.command() async def test(ctx, *args): await ctx.send('{} arguments: {}'.format(len(args), ', '.join(args))) ``` -------------------------------- ### event_party_member_ready_change Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Called when a member's ready state has changed. ```APIDOC ## event_party_member_ready_change ### Description Called when a member's ready state has changed. ### Parameters - **member** (PartyMember) - Required - The member that changed. - **before** (ReadyState) - Required - The previous ready state. - **after** (ReadyState) - Required - The current ready status. ``` -------------------------------- ### Reply to a friend message in event_friend_message Source: https://github.com/terbau/fortnitepy/blob/master/docs/faq.rst Use FriendMessage.reply() to respond to a friend message. The message.author.send() method is an alternative that also works. ```python @client.event async def event_friend_message(message): await message.reply('Thanks for the message!') # Not as clean but would still work: await message.author.send('Thanks for the message!') ``` -------------------------------- ### event_party_member_confirm Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Event called when a member asks to join the party. This event is automatically handled by the client which automatically always accepts the user. If you have this event referenced in your code the client won't automatically handle it anymore and you must handle it yourself. ```APIDOC ## event_party_member_confirm ### Description Event called when a member asks to join the party. This event is automatically handled by the client which automatically always accepts the user. If you have this event referenced in your code the client won't automatically handle it anymore and you must handle it yourself. ### Parameters - **confirmation** (PartyJoinConfirmation) - Required - Confirmation object with accessible confirmation methods. ``` -------------------------------- ### Custom callable converter with to_upper Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Uses a custom function as a converter to transform the argument to uppercase. The 'up' command sends the uppercased content. ```python def to_upper(argument): return argument.upper() @bot.command() async def up(ctx, *, content: to_upper): await ctx.send(content) ``` -------------------------------- ### event_command(ctx) Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst An event that is called when a command is found and is about to be invoked. This event is called regardless of whether the command itself succeeds via error or completes. ```APIDOC ## event_command(ctx) ### Description An event that is called when a command is found and is about to be invoked. This event is called regardless of whether the command itself succeeds via error or completes. ### Parameters - **ctx** (:class:`.Context`) - The invocation context. ``` -------------------------------- ### Cog.get_listeners Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/cogs.rst Returns a list of tuples containing event listener names and their corresponding functions. ```APIDOC ## Cog.get_listeners ### Description Returns a list of tuples containing event listener names and their corresponding functions. ### Method Cog.get_listeners ### Parameters None ### Returns - **list** - A list of tuples (listener_name, function). ### Example ```python for name, func in cog.get_listeners(): print(name, '->', func) ``` ``` -------------------------------- ### bool converter logic Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Shows the internal logic of the bool converter, which evaluates the argument as True or False based on its content. ```python if lowered in ('yes', 'y', 'true', 't', '1', 'enable', 'on'): return True elif lowered in ('no', 'n', 'false', 'f', '0', 'disable', 'off'): return False ``` -------------------------------- ### event_party_member_join Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Event called when a new member has joined ClientUser's party. ```APIDOC ## event_party_member_join ### Description Event called when a new member has joined ClientUser's party. ### Parameters - **member** (PartyMember) - Required - The member who joined. ``` -------------------------------- ### Command with owner and party checks Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Defines a command 'secret' that requires the owner and party membership. The error handler catches CheckFailure and sends a message. ```python3 @bot.command() @commands.is_owner() @in_party() async def secret(ctx): """super secret stuff""" await ctx.send('secret stuff') @secret.error async def secret_error(ctx, error): if isinstance(error, commands.CheckFailure): await ctx.send('nothing to see here comrade.') ``` -------------------------------- ### Advanced converter with Slapper class Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Defines a custom converter by subclassing commands.Converter and overriding convert. The converter randomly selects a party member and formats a slap message. ```python import random class Slapper(commands.Converter): async def convert(self, ctx, argument): to_slap = random.choice(list(ctx.bot.party.members)) return '{0.author} slapped {1} because *{2}*'.format(ctx, to_slap, argument) @bot.command() async def slap(ctx, *, reason: Slapper): await ctx.send(reason) ``` -------------------------------- ### Enumerations Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Enumerations used in fortnitepy for various settings and states. ```APIDOC ## Enumerations ### Description Enumerations used in fortnitepy for various settings and states. ### PartyPrivacy Specifies the privacy used in parties created by the client. - **PUBLIC** - Completely public, everyone can join. - **FRIENDS_ALLOW_FRIENDS_OF_FRIENDS** - Friends only, but friends of friends can join. - **FRIENDS** - Friends only. - **PRIVATE_ALLOW_FRIENDS_OF_FRIENDS** - Private but allows friends of friends. - **PRIVATE** - Private, no friends of friends. ### V2Input An enumeration for valid input types used for stats. - **KEYBOARDANDMOUSE** - Keyboard and mouse input. - **GAMEPAD** - Gamepad/controller input. - **TOUCH** - Touch display input. ### Region An enumeration for all currently available Fortnite regions. - **NAEAST** - North America East. - **NAWEST** - North America West. - **EUROPE** - Europe. - **BRAZIL** - Brazil. - **OCEANIA** - Oceania. - **ASIA** - Asia. - **MIDDLEEAST** - Middle East. ### Platform An enumeration for all currently available platforms. - **WINDOWS** - **MAC** - **PLAYSTATION_4** (also accessible as PLAYSTATION) - **PLAYSTATION_5** - **XBOX_ONE** (also accessible as XBOX) - **XBOX_X** - **SWITCH** - **IOS** - **ANDROID** ### ReadyState An enumeration for the available ready states. - **READY** - **NOT_READY** - **SITTING_OUT** ### UserSearchPlatform - **EPIC_GAMES** - All platforms using Epic Games as account service (PC, Mobile). - **PLAYSTATION** - **XBOX** - **STEAM** ### ProfileSearchMatchType - **EXACT** - Prefix matched display name perfectly. - **PREFIX** - Prefix matched start of display name. ### AwayStatus - **ONLINE** - User is active. - **AWAY** - User set status to away. - **EXTENDED_AWAY** - User is AFK. ### SeasonStartTimestamp An enumeration of season start dates. - **SEASON_1** through **SEASON_12** ### SeasonEndTimestamp An enumeration of season end dates. - (No attributes listed in source) ``` -------------------------------- ### event_party_join_request Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Event called when a friend requests to join your private party. ```APIDOC ## event_party_join_request ### Description Event called when a friend requests to join your private party. ### Parameters - **request** (PartyJoinRequest) - Required - Request object. ``` -------------------------------- ### Positional parameter command Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Defines a command with a single positional parameter that sends the argument back. ```python3 @bot.command() async def test(ctx, arg): await ctx.send(arg) ``` -------------------------------- ### event_party_member_match_players_left_change(member, before, after) Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst This event is called when the servercount changes in the match the member is currently in. It provides the member, the previous servercount, and the new servercount. ```APIDOC ## event_party_member_match_players_left_change(member, before, after) ### Description This event is called when the servercount changes in the match the member is currently in. ### Parameters - **member** (PartyMember) - The member that changed. - **before** (int) - The previous servercount. - **after** (int) - The new and current servercount. ``` -------------------------------- ### Fortnitepy PartyMember converter Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Uses the built-in fortnitepy.PartyMember converter to receive a PartyMember object as an argument. The command sends a message with the member's join date. ```python @bot.command() async def joined(ctx, *, member: fortnitepy.PartyMember): await ctx.send('{0} joined on {0.joined_at}'.format(member)) ``` -------------------------------- ### event_party_member_match_players_left_change(member, before, after) Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst This event is called when a member joins or leaves a match. It provides the member, the previous match state, and the new match state. ```APIDOC ## event_party_member_match_players_left_change(member, before, after) ### Description This event is called when a member joins or leaves a match. ### Parameters - **member** (PartyMember) - The member that changed. - **before** (bool) - The previous match state. - **after** (bool) - The new and current match state. ``` -------------------------------- ### event_friend_request(request) Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Called when the client receives a friend request. ```APIDOC ## event_friend_request(request) ### Description Called when the client receives a friend request. ### Method Event ### Parameters - **request** (Union[IncomingPendingFriend, OutgoingPendingFriend]) - Required - Request object. ``` -------------------------------- ### event_party_invite Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Event called when a party invitation is received. ```APIDOC ## event_party_invite ### Description Event called when a party invitation is received. ### Parameters - **invitation** (ReceivedPartyInvitation) - Required - Invitation object. ``` -------------------------------- ### Custom converter subclassing PartyMemberConverter Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Defines a converter by subclassing commands.PartyMemberConverter and overriding the convert method. The convert method receives ctx and argument, and is used as a building block for other converters. ```python3 class MemberOutfit(commands.PartyMemberConverter): async def convert(self, ctx, argument): pass ``` -------------------------------- ### event_party_member_promote Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Event called when a new partyleader has been promoted. ```APIDOC ## event_party_member_promote ### Description Event called when a new partyleader has been promoted. ### Parameters - **old_leader** (PartyMember) - Required - Member that was previously leader. - **new_leader** (PartyMember) - Required - Member that was promoted. ``` -------------------------------- ### Reload extension with bot.reload_extension Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/extensions.rst Reloads an extension by name, applying any changes made to the extension file. If an error occurs during reload, the bot behaves as if the reload never happened. ```python3 >>> bot.reload_extension('hello') ``` -------------------------------- ### event_party_member_battlepass_info_change Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Event called when a member's battlepass info has been changed. ```APIDOC ## event_party_member_battlepass_info_change(member, before, after) ### Description This event is called when a member's battlepass info has been changed. ### Parameters - **member** (PartyMember) - The member that changed. - **before** (tuple) - The previous battlepass data. Same structure as `PartyMember.battlepass_info`. - **after** (tuple) - The current battlepass data. Same structure as `PartyMember.battlepass_info`. ``` -------------------------------- ### Send a direct message to a friend Source: https://github.com/terbau/fortnitepy/blob/master/docs/faq.rst Use Friend.send() to send a direct message to a friend. Requires the Friend object obtained via client.get_friend(). ```python friend = client.get_friend('7e9f8dd37a924496bc5083733887b44c') await friend.send('Hello friend!') ``` -------------------------------- ### event_command_completion(ctx) Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst An event that is called when a command has completed its invocation. This event is called only if the command succeeded, i.e. all checks have passed and the user input it correctly. ```APIDOC ## event_command_completion(ctx) ### Description An event that is called when a command has completed its invocation. This event is called only if the command succeeded, i.e. all checks have passed and the user input it correctly. ### Parameters - **ctx** (:class:`.Context`) - The invocation context. ``` -------------------------------- ### Use cogs for inter-command communication Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/cogs.rst Shows two cogs: Economy and Gambling. Gambling retrieves the Economy cog via bot.get_cog('Economy') to call its methods, demonstrating how cogs can share data. ```python3 class Economy(commands.Cog): ... async def withdraw_money(self, member, money): # implementation here ... async def deposit_money(self, member, money): # implementation here ... class Gambling(commands.Cog): def __init__(self, bot): self.bot = bot def coinflip(self): return random.randint(0, 1) @commands.command() async def gamble(self, ctx, money: int): """Gambles some money.""" economy = self.bot.get_cog('Economy') if economy is not None: await economy.withdraw_money(ctx.author, money) if self.coinflip() == 1: await economy.deposit_money(ctx.author, money * 1.5) ``` -------------------------------- ### Custom check with exception and error handler Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Shows a custom check that raises a derived exception when the context has no party, and an error handler that catches it. The built-in party_only decorator is also available. ```python3 class PartyMessageOnly(commands.CheckFailure): pass def party_only(): async def predicate(ctx): if ctx.party is None: raise PartyMessageOnly('Hey no DMs!') return True return commands.check(predicate) @party_only() async def test(ctx): await ctx.send('Hey this is not a DM! Nice.') @test.error async def test_error(ctx, error): if isinstance(error, PartyMessageOnly): await ctx.send(error) ``` -------------------------------- ### Checks Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/api.rst Decorator functions used to add checks to commands. ```APIDOC ## Checks ### Description Decorator functions used to add checks to commands. ### Functions - `fortnitepy.ext.commands.check` - `fortnitepy.ext.commands.check_any` - `fortnitepy.ext.commands.cooldown` - `fortnitepy.ext.commands.max_concurrency` - `fortnitepy.ext.commands.before_invoke` - `fortnitepy.ext.commands.after_invoke` - `fortnitepy.ext.commands.party_only` - `fortnitepy.ext.commands.dm_only` - `fortnitepy.ext.commands.is_owner` ``` -------------------------------- ### Global check to block DMs Source: https://github.com/terbau/fortnitepy/blob/master/docs/ext/commands/commands.rst Registers a global check that blocks all DMs by returning True only when a party exists. Be careful as it can lock you out of your own bot. ```python3 @bot.check async def globally_block_dms(ctx): return ctx.party is not None ``` -------------------------------- ### event_auth_refresh() Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Called when the client's authentication has been refreshed. ```APIDOC ## event_auth_refresh() ### Description Called when the client's authentication has been refreshed. ### Method Event ### Parameters None ``` -------------------------------- ### event_invalid_party_invite Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Event called whenever you received an invite that was invalid. Usually this is because the invite was from a private party you have been kicked from. ```APIDOC ## event_invalid_party_invite ### Description Event called whenever you received an invite that was invalid. Usually this is because the invite was from a private party you have been kicked from. ### Parameters - **friend** (Friend) - Required - The friend that invited you. ``` -------------------------------- ### event_party_member_backpack_change Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Called when a member's backpack has been changed. ```APIDOC ## event_party_member_backpack_change ### Description Called when a member's backpack has been changed. ### Parameters - **member** (PartyMember) - Required - The member that changed. - **before** (str) - Required - The previous backpack bid. - **after** (str) - Required - The current backpack bid. ``` -------------------------------- ### event_friend_request_decline(friend) Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Called when a friend request is declined. ```APIDOC ## event_friend_request_decline(friend) ### Description Called when a friend request is declined. ### Method Event ### Parameters - **request** (Union[IncomingPendingFriend, OutgoingPendingFriend]) - Required - Request object. ``` -------------------------------- ### event_party_invite_decline Source: https://github.com/terbau/fortnitepy/blob/master/docs/api.rst Called when an invite has been declined. ```APIDOC ## event_party_invite_decline ### Description Called when an invite has been declined. ```