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
#Pycord V3 Events
1 messages · Page 1 of 1 (latest)
i have not asked for advice i want to try v3 and pycord v2 i know how to do that
I dont even know if its still bot.listen or other stuff
I have made it to discord pycord guid so I am waiting for a v3 supporter
Main devs @arctic turtle and @gloomy quiver are really the only guys who are familiar with it right now
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
or how can i create a loop?
there is currently no tasks framework
OH OKAY
Okay and for the other for example the guild count
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
v3 events have been remade to be class-based
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
bot.guilds is async now because the cache system is async as well, so you'd need to do something like await bot.guilds instead, and guild.members don't exist with v3 yet iirc
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?
no
pycord.File only exists on the routes branch
Okay, but how can I Set the Image of a embed with a local file?
Not currently possible with v3, was it even possible on v2?
?tag localfile
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)```
Ah I see, I'll have to add that later
oh o0kay
but i can usecogs or gears but not this tow together
what?
What is gears?
Can I use the normal cogs in v3 or only geras
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)
only gears
cogs are fully gone in v3, and are not coming back in any official form
Okay
You really should wait with it ;3
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
Yeah its right
I know that a basic slash_command work
iirc slash commands work with full functionality and aren't planned to get any real substantial changes any time soon, it's just components which are finnicky and are definitely getting a rewrite soon
though priority 1 is the routes pr before any other changes can really be done
I mean its hard to make the v3
gears looks like a slashcommandgroup
do you want to see slash command groups?
Uh yes! X3
@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')
What's Prelude?
Smth like context?
something like ApplicationContext yes
it's a higher-level wrapper around Interaction
Hmm. I thought it was going to be Interaction only 👀
.respond can only be used once while .send uses followup if you've already responded
well I kinda thought it'd be best to add something like context for easier migration. Prelude is a sub class of Interaction so it can be used in the same way if preferred
Oh ic