#Pycord ipc
1 messages · Page 1 of 1 (latest)
i can t use discord.ext import ipc
?
or you recomand this lib?
@pastel sandal
and how can i install better-ipc for pycord?
is that maintained anymore?
just install it and use as shown in the examples
idk
ok i try and say if it works thx for taking from your time to help me
import json
from discord.ext import commands
from discord.ext.ipc.server import Server
from discord.ext.ipc.objects import ClientPayload
with open('config.json', 'r') as config:
data = json.load(config)
bot_config = data["bot_config"]
ipc_key = bot_config["ipc_key"]
class Routes(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
if not hasattr(bot, "ipc"):
bot.ipc = Server(self.bot, secret_key=ipc_key) # type: ignore
async def cog_load(self) -> None:
await self.bot.ipc.start() # type: ignore
async def cog_unload(self) -> None:
await self.bot.ipc.stop() # type: ignore
del self.bot.ipc # type: ignore
@Server.route()
async def get_user_data(self, data: ClientPayload) -> Dict:
user = self.bot.get_user(data.user_id)
return user._to_minimal_user_json() # type: ignore
def setup(bot):
bot.add_cog(Routes(bot))```
don t work the ipc server not starting
i fix it but i want you to review my code please @pastel sandal
from typing import Dict
import json, asyncio
from discord.ext import commands
from discord.ext.ipc.server import Server
from discord.ext.ipc.objects import ClientPayload
with open('config.json', 'r') as config:
data = json.load(config)
bot_config = data["bot_config"]
ipc_key = bot_config["ipc_key"]
class Routes(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
if not hasattr(bot, "ipc"):
bot.ipc = Server(self.bot, secret_key=ipc_key)
print("Loading Routes cog...")
asyncio.create_task(self.bot.ipc.start())
def cog_unload(self):
print("Unloaded IPC")
asyncio.create_task(self.bot.ipc.stop())
@Server.route()
async def get_user_data(self, data: ClientPayload) -> Dict:
user = self.bot.get_user(data.user_id)
return user._to_minimal_user_json()
def setup(bot):
bot.add_cog(Routes(bot))```