Вот мой скрипт загрузки винтика
Код: Выделить всё
@client.event
async def on_ready():
for filename in os.listdir('cogs'):
if filename.endswith('.py'):
try:
client.load_extension(f'cogs.{filename[:-3]}')
except Exception as exception:
traceback.print_exc()
log.log(exception)
channel = client.get_channel(config.ERROR_LOG_CHANNEL_ID)
embed = nextcord.Embed(title=f"Failed to load {filename[:-3]}.",
description=f"{exception")
await channel.send(embed=embed)
Код: Выделить всё
import traceback
import asyncio
import nextcord
from nextcord.ext import commands
from static import config
from schildi import utils
import datetime
import os
from schildi import log
def user_action_embed(action: str, user: nextcord.Member, color: int, extra: str | None):
embed = nextcord.Embed(title="Audit Log Eintrag erstellt", description=action,
timestamp=datetime.datetime.now(), color=color)
embed.add_field(name="User", value=f"{user.mention} - {user.name}\n||{user.id}||", inline=False)
if extra:
embed.add_field(name="Zusatz", value=extra, inline=False)
return embed
class log_listener(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_guild_audit_log_entry_create(self, entry: nextcord.AuditLogEntry):
print(entry.action)
log_channel = self.client.get_channel(config.AUDIT_LOG_CHANNEL)
if entry.action == nextcord.AuditLogAction.thread_create:
await log_channel.send(embed=user_action_embed(
action="Thread create",
user=entry.user,
extra=f"{entry.extra.channel.mention}",
color=0x3efa5e))
if entry.action == nextcord.AuditLogAction.thread_delete:
await log_channel.send(embed=user_action_embed(
action="Thread delete",
user=entry.user,
extra=f"{entry.extra.channel.mention}",
color=0x3efa5e))
if entry.action == nextcord.AuditLogAction.thread_update:
await log_channel.send(embed=user_action_embed(
action="Thread create",
user=entry.user,
extra=f"{entry.extra.channel.mention}",
color=0x3efa5e))
def setup(client):
client.add_cog(log_listener(client))
Подробнее здесь: https://stackoverflow.com/questions/786 ... g-nextcord