Основу брал отсюда:
https://github.com/CodeWithSwastik/Dashboard-Tutor...
Первый файл main.py:
from quart import Quart, render_template, request, session, redirect, url_for
from quart_discord import DiscordOAuth2Session
from discord.ext import ipc
app = Quart(__name__)
ipc_client = ipc.Client(secret_key = "Swas")
app.config["SECRET_KEY"] = "test123"
app.config["DISCORD_CLIENT_ID"] = 726655948302843934 # Discord client ID.
app.config["DISCORD_CLIENT_SECRET"] = "TubLCh4tm09igxlscatfQdjcfgn3-AJq" # Discord client secret.
app.config["DISCORD_REDIRECT_URI"] = "http://127.0.0.1:5000/callback"
discord = DiscordOAuth2Session(app)
@app.route("/")
async def home():
return await render_template("index.html", authorized = await discord.authorized)
@app.route("/login")
async def login():
return await discord.create_session()
@app.route("/callback")
async def callback():
try:
await discord.callback()
except Exception:
pass
return redirect(url_for("dashboard"))
@app.route("/dashboard")
async def dashboard():
if not await discord.authorized:
return redirect(url_for("login"))
guild_count = await ipc_client.request("get_guild_count")
guild_ids = await ipc_client.request("get_guild_ids")
user_guilds = await discord.fetch_guilds()
guilds = []
for guild in user_guilds:
if guild.permissions.administrator:
guild.class_color = "green-border" if guild.id in guild_ids else "red-border"
guilds.append(guild)
guilds.sort(key = lambda x: x.class_color == "red-border")
name = (await discord.fetch_user()).name
return await render_template("dashboard.html", guild_count = guild_count, guilds = guilds, username=name)
@app.route("/dashboard/<int:guild_id>")
async def dashboard_server(guild_id):
if not await discord.authorized:
return redirect(url_for("login"))
guild = await ipc_client.request("get_guild", guild_id = guild_id)
if guild is None:
return redirect(f'https://discord.com/oauth2/authorize?&client_id={app.config["DISCORD_CLIENT_ID"]}&scope=bot&permissions=8&guild_id={guild_id}&response_type=code&redirect_uri={app.config["DISCORD_REDIRECT_URI"]}')
return guild["name"]
if __name__ == "__main__":
app.run(debug=True)
Выдает ошибку:
Traceback (most recent call last):
File "C:\Users\user\Desktop\dash\server.py", line 6, in <module>
ipc_client = ipc.Client(secret_key = "Swas")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Client.__init__() missing 1 required positional argument: 'client'
[Finished in 789ms]
Второй файл bot.py:
import discord
from discord.ext import commands, ipc
TOKEN = ""
class MyBot(commands.Bot):
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.ipc = ipc.Server(self,secret_key = "Swas")
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 server 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 = discord.Intents.default())
@my_bot.ipc.route()
async def get_guild_count(data):
return len(my_bot.guilds) # returns the len of the guilds to the client
@my_bot.ipc.route()
async def get_guild_ids(data):
final = []
for guild in my_bot.guilds:
final.append(guild.id)
return final # returns the guild ids to the client
@my_bot.ipc.route()
async def get_guild(data):
guild = my_bot.get_guild(data.guild_id)
if guild is None: return None
guild_data = {
"name": guild.name,
"id": guild.id,
"prefix" : "?"
}
return guild_data
@my_bot.command()
async def hi(ctx):
await ctx.send("Hi")
my_bot.ipc.start()
my_bot.run(TOKEN)
Выдает ошибку (такую же)
Traceback (most recent call last):
File "C:\Users\user\Desktop\dash\server.py", line 6, in <module>
ipc_client = ipc.Client(secret_key = "Swas")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Client.__init__() missing 1 required positional argument: 'client'
[Finished in 806ms]
Все библиотеки установил, правильно скопировал, пишу так как нем знаю решения