#Pycord V3 Events

1 messages · Page 1 of 1 (latest)

solar hill
#
import pycord
import datetime
import asyncio
import random
import os

#from discord.ext import commands

# from utils.funcs import connect
#from utils.funcs import get_config
# from utils.funcs import error_embed
# from utils.funcs import get_language
# from utils.funcs import get_database_tables

#intents = discord.Intents.all()

bot = pycord.Bot(intents=pycord.Intents())
#bot = commands.Bot(intents=intents, command_prefix=commands.when_mentioned_or("-"))
#bot.remove_command("help")

# def load_cogs(path, file):
#     for filename in os.listdir(f"{path}"):
#         if filename.endswith(".py"):
#             try:
#                 bot.load_extension(f"{file}{filename[:-3]}")
#                 print(f"| Xenority Module Loaded ---> {filename}")
#             except Exception as e:
#                 print(f"Failed to Load {filename}")
#                 print(f"[ERROR] {e}")

# load_cogs("./cogs/xenority", "cogs.xenority.")
# load_cogs("./cogs", "cogs.")

# --------------------------  Events  -------------------------- #

@bot.listen
async def on_ready():
    bot.loop.create_task(change_status())
    bot.loop.create_task(clean_temp())
    #vanity_task.start()
    print(f"|-------------------------------------------------------------|")
    print(f"""|    ____                                 _                _  |
|   / ___|   ___    _ __     ___    ___  | |_    ___    __| | |
|  | |      / _ \  | '_ \   / _ \  / __| | __|  / _ \  / _` | |
|  | |___  | (_) | | | | | |  __/ | (__  | |_  |  __/ | (_| | |
|   \____|  \___/  |_| |_|  \___|  \___|  \__|  \___|  \__,_| |""")
    print(f"|                                                             |")
    print(f"|-------------------------------------------------------------|")
    # my_list = get_database_tables()
    # for i in range(len(my_list)):
    #     print(f"| Loaded Database Table: "+ my_list[i])
    print(f"|-------------------------------------------------------------|")
    print(f"| Der Bot ---> {bot.user} <--- ist Online ")
    print(f"|                                                             |")
    print(f"| Guilds ---> {len(bot.guilds)} Users: {sum([len(guild.members) for guild in bot.guilds])}")
    print(f"|-------------------------------------------------------------|")

@bot.listen
async def clean_temp():
    while True:
        try:
            files = [file for file in os.listdir("./temp")]
            for file in files:
                # print(files)
                timestemp  = os.stat(f"./temp/{file}").st_mtime
                data = datetime.datetime.fromtimestamp(timestemp)
                if datetime.datetime.now() - datetime.timedelta(seconds=30) > data:
                    os.remove(f"./temp/{file}")
                    print("Gelöscht")
            await asyncio.sleep(10)
        except:
            pass

@bot.listen
async def change_status():
    while True:
        try:
            await bot.change_presence(
                activity=pycord.Streaming(name="Xenority Network", url="httpymann2000hd"))
            await asyncio.sleep(10)
            list = ["Xenority Network", f"on {len(bot.guilds)} servers", "dis9sm82"]
            text = random.choice(list)
            await bot.change_presence(activity=pycord.Game(
                name=text,
                status=pycord.Status.online))
            await asyncio.sleep(10)
        except:
            pass
#

i have noz a error but the events not staarts

lean seal
#

stay with v2

#

v3 is still developing

solar hill
lean seal
#

I dont even know if its still bot.listen or other stuff

solar hill
crude lion
#

Main devs @arctic turtle and @gloomy quiver are really the only guys who are familiar with it right now

solar hill
#

i have found the issue how can i amke this with v3
print(f"| Guilds ---> {len(bot.guilds)} Users: {sum([len(guild.members) for guild in bot.guilds])}")
len are not vaaild with guilds

solar hill
#

or how can i create a loop?

gloomy quiver
#

there is currently no tasks framework

solar hill
#

OH OKAY

solar hill
#

Okay and for the other for example the guild count

crude lion
#

I think V2 tasks ext will work with V3 because it doesn't use Bot at all

#

Only things it uses is exponential backoff

#

Which is also a thing of its own and doesn't rely on any other discord stuff

arctic turtle
#

So you'd need to do something like:

@bot.listen()
async def on_ready(event: pycord.Ready) -> None:
    ...
#

And bot.loop doesn't exist anymore, just use asyncio.create_task or it's other subsidies

arctic turtle
solar hill
#

okay, is the bot status implementet? for change the bot status from online to dnd

#

ând a ohter queatio is it corret from pycord import Embed? (for create a embed without a bot class)
and is for a embed file pycord.File correct?

arctic turtle
solar hill
#

Okay, but how can I Set the Image of a embed with a local file?

arctic turtle
wraith patioBOT
#
f = discord.File("some_file_path", filename="image.png")
e = discord.Embed()
e.set_image(url="attachment://image.png")
await messagable.send(file=f, embed=e)```
arctic turtle
#

Ah I see, I'll have to add that later

solar hill
#

oh o0kay

solar hill
#

but i can usecogs or gears but not this tow together

lean seal
arctic turtle
#

works really simple

solar hill
#

Can I use the normal cogs in v3 or only geras

arctic turtle
#
import pycord
from pycord.ext import gears

gear = gears.Gear('my_gear', gears.BaseContext())

@gear.command()
async def my_command(pre: pycord.Prelude) -> None:
  ...

# later on
gear.attach(bot)
arctic turtle
#

cogs are fully gone in v3, and are not coming back in any official form

solar hill
#

Okay

lean seal
#

You really should wait with it ;3

solar hill
#

I dont wqit I will test it out

arctic turtle
# solar hill I dont wqit I will test it out

sure, but please don't try to make any real bots with it, v3 is still experimental in most places so anything can get removed, renamed, or replaced at any point without warning

solar hill
#

Yeah its right

lean seal
#

I know that a basic slash_command work

arctic turtle
#

though priority 1 is the routes pr before any other changes can really be done

solar hill
#

I mean its hard to make the v3

lean seal
#

gears looks like a slashcommandgroupsaisneaky

arctic turtle
lean seal
#

Uh yes! X3

arctic turtle
#
@bot.command()
async def root(pre: pycord.Prelude) -> None:
  # this is ran at the same time as sub commands, and so can be used to do whatever
  ...

@root.command()
async def child(pre: pycord.Prelude) -> None:
  await pre.send('wee')
crude lion
#

Smth like context?

arctic turtle
#

it's a higher-level wrapper around Interaction

crude lion
#

Hmm. I thought it was going to be Interaction only 👀

arctic turtle
#

.respond can only be used once while .send uses followup if you've already responded

arctic turtle
crude lion
#

Oh ic