Example Usages ============== Here are some ways to use nextcord-ext-ipc in **your own bot!** For GitHub based examples, see `the examples directory `_. Basic IPC Implementation ------------------------- Your main bot file .. code-block:: python :linenos: import nextcord from nextcord.ext import commands, ipc class MyBot(commands.Bot): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ipc = ipc.Server(self, secret_key="my_secret_key") # create our IPC Server async def on_ready(self): """Called upon the READY event""" print("Bot is ready.") async def on_ipc_ready(self): """Called upon the IPC Server being ready""" print("IPC is ready.") async def on_ipc_error(self, endpoint, error): """Called upon an error being raised within an IPC route""" print(endpoint, "raised", error) my_bot = MyBot(command_prefix="!", intents=nextcord.Intents.all()) @my_bot.ipc.route() async def get_member_count(data): guild = my_bot.get_guild( data.guild_id ) # get the guild object using parsed guild_id return guild.member_count # return the member count to the client if __name__ == "__main__": my_bot.ipc.start() # start the IPC Server my_bot.run("TOKEN") Your bot's webserver file .. code-block:: python :linenos: from quart import Quart from nextcord.ext import ipc app = Quart(__name__) ipc_client = ipc.Client( secret_key="my_secret_key" ) # secret_key must be the same as your server @app.route("/") async def index(): # get the member count of the guild with the id 12345678 member_count = await ipc_client.request("get_member_count", guild_id=12345678) # display member count return str(member_count) if __name__ == "__main__": app.run() Cog based IPC implementation ----------------------------- The bot file: .. code-block:: python :linenos: import nextcord from nextcord.ext import commands, ipc class MyBot(commands.Bot): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.ipc = ipc.Server(self, secret_key="my_secret_key") # create our IPC Server self.load_extension("cogs.ipc") # load the IPC Route cog async def on_ready(self): """Called upon the READY event""" print("Bot is ready.") async def on_ipc_ready(self): """Called upon the IPC Server being ready""" print("IPC is ready.") async def on_ipc_error(self, endpoint, error): """Called upon an error being raised within an IPC route""" print(endpoint, "raised", error) my_bot = MyBot(command_prefix="!", intents=nextcord.Intents.all()) if __name__ == "__main__": my_bot.ipc.start() # start the IPC Server my_bot.run("TOKEN") The cog file: .. code-block:: python :linenos: from nextcord.ext import commands, ipc class IpcRoutes(commands.Cog): def __init__(self, bot): self.bot = bot @ipc.server.route() async def get_member_count(self, data): guild = self.bot.get_guild( data.guild_id ) # get the guild object using parsed guild_id return guild.member_count # return the member count to the client def setup(bot): bot.add_cog(IpcRoutes(bot)) The webserver file: .. code-block:: python :linenos: from quart import Quart from nextcord.ext import ipc app = Quart(__name__) ipc_client = ipc.Client( secret_key="my_secret_key" ) # secret_key must be the same as your server @app.route("/") async def index(): member_count = await ipc_client.request( "get_member_count", guild_id=12345678 ) # get the member count of server with ID 12345678 return str(member_count) # display member count if __name__ == "__main__": app.run()