API Reference

Discord.py IPC Extension

A upgraded version of discord-ext-ipc that now works with discord.py v2.

copyright:
  1. 2020-present Ext-Creators, No767

license:

Apache-2.0, see LICENSE for more details

Client

class discord.ext.ipcx.Client(host: str = 'localhost', port: int | None = None, multicast_port: int = 20000, secret_key: str | None = None)

Handles webserver side requests to the bot process.

Operations with async with will automatically initialize the client and automatically cleans up.

Parameters:
  • host (str) – The IP or host of the IPC server, defaults to localhost

  • Optional[port] (int) – The port of the IPC server. If not supplied the port will be found automatically, defaults to None

  • multicast_port (Optional[int]) – The mutlicast post of the IPC server. If not supplied, the port used will be 20000.

  • secret_key (Union[str, bytes]) – The secret key for your IPC server. Must match the server secret_key or requests will not go ahead, defaults to None

async close() None

Properly closes the aiohttp.ClientSession session used for connections

Warning

This is required in order to clean up any remaining connections held in aiohttp.ClientSession. Without doing so, your webserver will complain about having an unclosed client session, which is the result of not closing it manually.

async request(endpoint: str, **kwargs) Any

Make a request to the IPC server process.

Parameters:
  • endpoint (str) – The endpoint to request on the server

  • **kwargs – The data to send to the endpoint

Server

class discord.ext.ipcx.Server(bot: Bot, host: str = 'localhost', port: int = 8765, secret_key: str | None = None, do_multicast: bool = True, multicast_port: int = 20000)

The IPC server. Usually used on the bot process for receiving requests from the client.

bot

Your bot instance. Subclassed bot instances should work as well.

Type:

Bot

host

The host to run the IPC Server on. Defaults to localhost.

Type:

str

port

The port to run the IPC Server on. Defaults to 8765.

Type:

int

secret_key

A secret key. Used for authentication and should be the same as your client’s secret key.

Type:

str

do_multicast

Turn multicasting on/off. Defaults to True

Type:

bool

multicast_port

The port to run the multicasting server on. Defaults to 20000

Type:

int

async handle_accept(request: Request)

Handles websocket requests from the client process.

Parameters:

request (Request) – The request made by the client, parsed by aiohttp.

async handle_multicast(request: Request)

Handles multicasting websocket requests from the client.

Parameters:

request (Request) – The request made by the client, parsed by aiohttp.

route(name=None)

Used to register a coroutine as an endpoint when you have access to an instance of Server.

Parameters:

name (str) – The endpoint name. If not provided the method name will be used.

async start() None

Starts the IPC server.

update_endpoints()

Called internally to update the server’s endpoints for cog routes.

discord.ext.ipcx.route(name: str | None = None)

Used to register a coroutine as an endpoint when you don’t have access to an instance of Server

Parameters:

name (Optional[str]) – The endpoint name. If not provided the method name will be used.

Exceptions

exception discord.ext.ipcx.errors.IPCError

Base IPC exception class

exception discord.ext.ipcx.errors.JSONEncodeError

Raise upon un-serializable objects are given to the IPC

exception discord.ext.ipcx.errors.NoEndpointFoundError

Raised upon requesting an invalid endpoint

exception discord.ext.ipcx.errors.NotConnectedError

Raised upon websocket not connected

exception discord.ext.ipcx.errors.ServerConnectionRefusedError

Raised upon a server refusing to connect / not being found