#Basic Pycord Help

1 messages · Page 75 of 1

fresh sierra
#

is there a way to globally ignore those when using meta ?

fresh sierra
#

is any is getting deprecated, what is the alternative ?

echo wraith
#
executionEnvironments = [
  { root = "src/database/models", blaBluh= false }
]

@fresh sierra

#

in pyproject

echo wraith
#

is it ?

fresh sierra
echo wraith
#

that was my point

fresh sierra
#

mb then

#

getting a bit chunky but everything for typehint ig

#

only 200k lines left to do

echo wraith
#

😭

echo wraith
fresh sierra
echo wraith
#

ok

#

I really think you should consider postgres given how many json / list fields you have

fresh sierra
#

mysql is setup by defualt with pterodactyl i think

#

but its ok doing like this is enough

#

rn im trying to find all thing i should ignore

echo wraith
echo wraith
fresh sierra
#

to see all of the thing i can do using this

echo wraith
fresh sierra
#

when i dont know how to typehint a dict, what should i do ?

    @staticmethod
    def load_yaml(file_path: str) -> dict[]:
        """Load a YAML file and return its contents."""
        with open(file_path, "r", encoding="utf-8") as file:
            return yaml.safe_load(file)
echo wraith
#

so probably

#

dict[str, Any]

#

Also

#

you should probably add

#

to your pyproject

#
typeCheckingMode = "all"
reportAny = false
reportExplicitAny = true
#

Also make sure you're actually using based pyright and not just pyright

fresh sierra
#

rn im using pylance, i tried using basepyright but too much error, i'll see to switch when its already done with pyright

echo wraith
#

also

#

you could use baseline

#

which will ignore all your errors

#

and allow you to gradually type your code

#

but baseline is only in basedpyright

fresh sierra
#

idk what is baseline, do you have some docs ?

fresh sierra
#

are they better way to typehint this that this longggggg dict etc etc

echo wraith
#

e.g. of baseline

fresh sierra
fresh sierra
echo wraith
#

so you can create a type alisas

#

TranslationDict: TypeAlias = blah blah

fresh sierra
fresh sierra
#

im at 8k rn (using only half of my code tho

echo wraith
#

btw

echo wraith
fresh sierra
echo wraith
#

in 3 years probably

fresh sierra
#

guess how many error i have

#

on lumabot v2

echo wraith
#

16k

fresh sierra
#

more

echo wraith
#

22k

fresh sierra
echo wraith
#

bruh

silk spire
echo wraith
#

yeah

#

you edited

#

there is any but it's completely a differen thing it wouldn't make sense to replace it with

fresh sierra
silk spire
#

Yeah

fresh sierra
#

38errors for that...

#

how can this masterpiece be an error

silk spire
#

Raw string moment

#

r"""xxx"""

fresh sierra
#

waouw

#

we learn thing everyday

#

its red also now

#

which is kinda cool

silk spire
#

Huh I never noticed that lol

fresh sierra
silk spire
#

Damn yeah

#

Lovely outline

fresh sierra
#

is there a way to ignore lib errors ?

echo wraith
#

For a long time I only used r in regexes and so I thought r was for regex and only laterearnt it was raw

silk spire
#

Lool

grizzled loom
#

Up to Python 3.9, yes. Above Both Version are valid, cause it is any type but inside a tuple when you work with args and kwargs. One is less typing, the other more precise. Both are valid and accepted.

silk spire
#

TIL

#

that's neat

silk spire
echo wraith
#

3 is best also imo

silk spire
#

Not if they use a whole protocol with all the params kek

echo wraith
#

No it will be an assign error

#

Like it will say you can't assign respond to that

silk spire
#

Ahh

echo wraith
#

Because respond is partially unknown

#

Yeah

silk spire
#

Right

fresh sierra
#

but im gonna do 3

echo wraith
silk spire
#
  1. Force someone else (cough paillat cough) to PR a fix
fresh sierra
#
  1. Force plun to merge that not in 4months
echo wraith
fresh sierra
#

if i have a subclass of ctx, can i just change it ?

echo wraith
#

Maybe

fresh sierra
#

like something like this

echo wraith
#

You'll probably get incompatible override but yeah

echo wraith
#

More like

#

AsNc def respond

fresh sierra
#

also annoying because i do lose the docs

echo wraith
#

¯_(ツ)_/¯

fresh sierra
#

even command raise error...

echo wraith
#

Yeah cause kwarg :)

fresh sierra
#

i think im gonna just give up

#

because if i need to "fix" also every error by pycord im not done

fresh sierra
#

will there be a way for a typehint to automatically set bot.user to the ClientUser in event, commands etc since we cannot receive events if we are not logged in

silk spire
#

Just do it yourself,

class MyBot(Bot):
    user: discord.ClientUser. # type: ignore

It won't be none ever really

summer knot
#

Does anyone know how to make these types of embeds?

sage tendon
#

components v2, not possible in pycord yet, its a PR

fresh sierra
sly karmaBOT
# summer knot Does anyone know how to make these types of embeds?

Components V2 are under development in pycord and aren't yet included in the official releases on PyPI or the master GitHub branch. However, you can access the features now by installing directly from the pull request #2707. To do this, use the following command: pip install git+https://github.com/Pycord-Development/pycord.git@refs/pull/2707/head Please be aware that this is a development version and may contain bugs, feel free to report them by adding a comment to the pull request.

silk spire
fresh sierra
torn barn
#

and you are overriding it as an attribute, so the docs are missing

fresh sierra
#

If not that’s not a big issue

torn barn
#

the utils copies the doc of a function to another, nothing else

#

just override it as a property

#

and not as an attribute

#
class MyBot(Bot):
    @property
    def user(self) -> discord.ClientUser:
        return super().user  # type: ignore
fresh sierra
#

ok thanks !

fresh sierra
#

i dont really get how im supposed to make the fix this

#

how can i define it

Type of "__init__" is partially unknown
  Type of "__init__" is "(*items: Item[Unknown], timeout: float | None = 180, disable_on_timeout: bool = False) -> None"
sage tendon
#

at some point typing is just a hindrance

errant trout
#

well yeah but that's what they signed up for

#

kinda like using typescript

tidal pecan
sage tendon
#

voidCaster missing the point, episode 5981

silk spire
fresh sierra
tidal pecan
sage tendon
#

reading comprehension is hard

errant trout
#

but i might be completely wrong, i don't use pyright

fresh sierra
errant trout
#

havefun

fresh sierra
errant trout
tidal pecan
fresh sierra
#

(also im using strict typing)

tidal pecan
#

I'm wondering if maybe you have too many imports now XD Like multiple objects are resolving to Item

sage tendon
#

sigh

sage tendon
#

its pycord code

fresh sierra
#

been trying to fix for 30min this error, only to find out that when using a stub file it raise this

fresh sierra
arctic plover
#

How do i get label of selected option in Select, not a value?

fresh sierra
sage tendon
#

the question is rather why you'd want the label, ever

errant trout
#

when recieving an interaction, discord only sends value - if you want the label for some reason, you would need to retrieve the SelectOption from Select.options; you can do something like discord.utils.get(options, value=value)

#

(basically iterate through options for a matching value)

arctic plover
fresh sierra
raw beacon
#

does pycord have cv2 docs yet for the dev build

sly karmaBOT
#

Components V2 are under development in pycord and aren't yet included in the official releases on PyPI or the master GitHub branch. However, you can access the features now by installing directly from the pull request #2707. To do this, use the following command: pip install git+https://github.com/Pycord-Development/pycord.git@refs/pull/2707/head Please be aware that this is a development version and may contain bugs, feel free to report them by adding a comment to the pull request.

raw beacon
#

Yeah

#

So no?

lapis dock
#

Oh you want docs specifically

raw beacon
#

yeah

lapis dock
#

There is a way to get them via direct URL I think, give me a second

lapis dock
#

FAQ page was not changed btw. Just what the link defaulted to

terse arrow
#

Hey all, I've built my bot project into an exe, however now that I've placed it onto a VPS, it is throwing this error. The bot has Admin perms in the discord, can anyone tell me why this is happening

terse arrow
little cobalt
#

Why did you convert it into a exe?

terse arrow
#

Thought it was a good way to combine it all together 🤷‍♂️

#

Simple to move and manage

little cobalt
#

To move and manage, you can use a .zip

terse arrow
#

But - I've also tried with a py file and it's complained the same way

terse arrow
errant trout
little cobalt
#

How can I set the slash commands only be visible at the Guild and not at the dm's?

wheat tiger
#

@fresh sierra Is there any way to get a TypedDict return type from a Tortoise ORM Model?

#

So that I can get type hints?

#

Currently I've to manually type it

wheat tiger
fresh sierra
#

Why do you need it typed as tupedict ?

wheat tiger
fresh sierra
fresh sierra
wheat tiger
#

it is returning dict

#

either normal dict or TypedDict works

fresh sierra
#

Why are you not changing ur function to say that it’s retuning the model I meant

wheat tiger
fresh sierra
wheat tiger
fresh sierra
wheat tiger
fresh sierra
fresh sierra
wheat tiger
fresh sierra
fresh sierra
wheat tiger
#

.<name>

#

Is there any way to make literals of the model (for param type)?

#

@fresh sierra

fresh sierra
wheat tiger
fresh sierra
#

def tst(function: GuildTable )

#

why you dont do like this ?

wheat tiger
#

lemme see if it works 💀

wheat tiger
#

in settings param I want to get the column names

fresh sierra
#

ooooo

#

wait

wheat tiger
#

So I had to create Literal[]

#

declaring the columns manually

fresh sierra
#
for field_name, field in StatsRoleTime._meta.fields_map.items():
wheat tiger
fresh sierra
wheat tiger
#

the for loop?

fresh sierra
#

where you need to get the field name

wheat tiger
wheat tiger
#

Like this

fresh sierra
wheat tiger
fresh sierra
wheat tiger
#

I don't get any autocomplete

fresh sierra
#

i dont think it come from this autocomplete

fresh sierra
#

like the create one

wheat tiger
#

How can I do global error handling for missing bot perms in slash commands?

lofty parcel
wheat tiger
lofty parcel
#

What

#

It's an event

#

You make it an event listener

wheat tiger
#

the isinstance() check

lofty parcel
#

Well what decorator for permissions are you using

wheat tiger
#

and for group slash commands, default_member_permissions

lofty parcel
#

That doesnt raise any error

#

It's not an internal check

wheat tiger
wheat tiger
#

like if bot doesn't has manage members permissions

#

then it will throw error

lofty parcel
#

They usually raise Forbidden

wheat tiger
#

Like the global exception

sterile herald
#

Is player a reserved word somewhere? I was trying to debug why my Cog commands were getting discord interaction errors, but changing it from this:

to this
player_check = discord.SlashCommandGroup('player_check', 'Player related commands.')
and the commands to @player_check.command fixed my error.

**Here is what I wrote below before I tried changing that, but I don't know why 'player' as the slash command group name would have been the cause. **

||Am I missing what is different between these two files? https://www.diffchecker.com/PFrH4C4N/

On the left-side is my original code, the right-side is the duplicated code.

With the original code, I was getting these errors if I spammed the interaction multiple times (or even with two accounts doing it once each at the same time). It would correctly respond sometimes, but the rest would error out.

discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: NotFound: 404 Not Found (error code: 10062): Unknown interaction
``` and
```py
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: HTTPException: 400 Bad Request (error code: 40060): Interaction has already been acknowledged.

I made the duplicate cog file with the identical code (different group name), and it will let me spam the command with no issues or errors.||

lapis dock
sterile herald
lapis dock
#

🎉

#

The reason I suspected that is because the new commands would only be on one instance not all so they would not have the same problem

lapis dock
#

Permissions names of what? The missing permissions?

lapis dock
eternal kite
#

Whenever i send a modal it raises an error saying the interaction has already been responded, but i have modal sends in other commands and they work fine, is there any reason causing this issue?

#

Also, are there timeouts for modals? if not, how can I handle timeouts to prevent memory leaks?

lapis dock
#

Modals do have timeouts you can pass them to the constructor. Modals need to be the response to an interaction not a followup. This means you cannot defer before sending a modal

#

@eternal kite pong

eternal kite
lapis dock
#

Can you share your code

eternal kite
#

so i spent a few hours debugging, and it turns out that newly registered commands are unable to send modals

fresh sierra
#

see the code would really help us locate the issue

eternal kite
#

i know dead

#

so this is how it's like

eternal kite
fresh sierra
# eternal kite

why are you using the import and not putting it directly inside the command ?

eternal kite
#

cuz it's cleaner

#

alr so i'll provide more clues so we can come up with a hypothesis with this weird bug

fresh sierra
#

are you saying that the modal is not sent at all

eternal kite
#

yes

#

error says the interaction has already been responded before

fresh sierra
#

because you are in fact answer 2 times to the interaction

eternal kite
#

also

#

no i swear that's literally the whole piece of code i have

fresh sierra
# eternal kite

inside the fonction that you import and inside the callback of the modal (im not sure about that idk if the interaction is renew or not)

eternal kite
#

so i have another command which also sends a modal when a user uses it, so in this code i replace the import slash function call from learn to faction_create, and i use the /learn command it works perfectly fine

eternal kite
#

in fact, i also used the exact same modal from the learn command

#

in the faction create command

#

and it didnt work as well

fresh sierra
# eternal kite

if inside ur callback hre for the modal you just have a return and nothing else

#

do it still raise an error already response

eternal kite
fresh sierra
#

are you also sure you dont have any group check or all which can lead to an interaction behing already answer

eternal kite
#

group check?

#

nah i dont think so

#

never knew group checks are a thing

#

only know bot checks

fresh sierra
#

what you could do to debug is to print ctx.interaction.response.is_done() and so you can then check before the thing if its alrady done or not

#

like one time before the import and then inside the faction create

eternal kite
#

good approach, haven't tried that yet

eternal kite
fresh sierra
#

use typehint

#

and you will see it

eternal kite
#

i checked the docs as well

#

Application Command raised an exception: AttributeError: 'Interaction' object has no attribute 'is_done'

errant trout
#

it's interaction.response.is_done()

eternal kite
#

oh

sage tendon
#

reading the docs helps

eternal kite
eternal kite
sage tendon
eternal kite
#

what i mentioned is the response didn't link to the interactionresponse

sage tendon
#

yea, happens sometimes

eternal kite
#

im puzzled rn

fresh sierra
#

to be sure

errant trout
#

You definitely have some function on your bot that's deferring every interaction

little cobalt
eternal kite
eternal kite
eternal kite
#

soo.. i actually have another similar command that sends modal, and it works just fine, when I change the function call to faction_create, it works fine as well

#

i've also tried removing the slash command group and used slash_command instead, still didn't work

#

OKAY i think i found the issue 💀

eternal kite
errant trout
#

Hey at least you found it

#

Deferring everything sounds good on paper but it's not practical

wheat tiger
#

Why is bot throwing this error on every autocomplete? Also the autocomplete isn't working...

#

(Using master branch)

fresh sierra
#

a group check ?

errant trout
eternal kite
#

i think i know why i added the check literally 2 years ago lol

#

now that i've removed it and half of the commands aren't working

wheat tiger
errant trout
#

Mmm last I checked there's nothing wrong with it on master but I can't test

wheat tiger
errant trout
#

"Future attached to a different loop" idk what you've done on your end

torn barn
#

@wheat tiger do you pass a custom event loop to your bot's init?

little cobalt
wheat tiger
#

check this

#

await DB().init() does this

little cobalt
#

That is by default at true

sage tendon
#

its forever beyond me how people overcomplicate cog loading (which can be 1 line) so hard

wheat tiger
sage tendon
#

idk about your bot but for me, loading 6 cogs takes 1 second

little cobalt
#

which DB did you use?

wheat tiger
sage tendon
#

but if you really want easy progress bars in the terminals, look into tqdm, its stupid easy

wheat tiger
#

@torn barn?

torn barn
#

yeah i cant seem to find the issue

#

enable asyncio debug mode then

wheat tiger
little cobalt
wheat tiger
wheat tiger
fresh sierra
# wheat tiger

does ur cog actually takes time to load cog for the progress bar looks nice ?

fresh sierra
fresh sierra
wheat tiger
#

this was before

wheat tiger
#

@fresh sierra How du use tortoise orm and start ur bot?

fresh sierra
#
async def main():
    try:
        await init()
        await bot.start(BOT_TOKEN)
    finally:
        await shutdown()
        if not bot.is_closed():
            await bot.close()


def run():
    bot.loop.run_until_complete(main())


if __name__ == "__main__":
    run()
wheat tiger
#

asyncio.run() was the evil

fresh sierra
wheat tiger
fresh sierra
wheat tiger
#

it would've fixed my issue

fresh sierra
#

nor u were asyncio.run

little cobalt
#

I used that a lot for my Stuff

#

Its pretty easy to use

fresh sierra
#

it might replace my pystyle

fresh sierra
wheat tiger
fresh sierra
#

thanks

#

what are you using uv for ?

wheat tiger
fresh sierra
#

im currently using poetry

#

should i change in ur opinon

#

and if yes why

wheat tiger
#

uv is actually fast tbh

#

much faster than poetry

#

also u should consider using it to manage py version (over pyenv) [if u don't use it on arm based machines]

fresh sierra
#

it the usage the same or i will have to setup more thing

#

rn i just have my poetry and a venv, and i do like poetry run bot, poetry install lock etc

#

show the outdated etc

wheat tiger
#

only the format differ

#

uv prioritizes PEP style (uses hatchling as backend) while poetry has it's own backend

fresh sierra
#

gonna check that maybe tomorrow after exams

wheat tiger
fresh sierra
upper hearth
#

with autocomplete in slash commands, does discord do their own filtering of results or something
if i type nothing i get the options
if i type something, even though i can see that OptionChoices are being returned, it shows no results

#

because the result doesn't start with what i've typed but i still want to return it

little cobalt
upper hearth
#

autocomplete

#

guessing i should use choices then

little cobalt
#

For what?

upper hearth
#

i have a list of things that have both names and IDS and i want to be searchable with both

#

but it only works with names

#

im guessing because discord is filtering out the optoins that don't start with the name

little cobalt
#

So, choices got a limit of 25 Items which dont update without a bot restart. Autocomplete does not have any limit and can always be updated

upper hearth
#

i'm just returning 1 thing at the minute

#

like theres just 1 thing in the list

#

but i just want it to return things that don't start with what the user has typed

little cobalt
#

From where did you got the information?

upper hearth
#

its just a list of [name, id]

#

it works if i type nothing or the name just not if i type the id

#

even though i can see optionchoice being returned

sage tendon
#

its fully up to you what you return to autocomplete inputs

#

And no, Discord doesn't filter autocomplete results, it doesnt have to start with what you are typing in the search box, it can be literally whatever

upper hearth
#

yeah that's what i hoped so something else is going on

#

why else would discord not show the optionchoice that i am returning

sage tendon
#

show your code, show the input you are doing in discord

upper hearth
#
async def card_searcher(ctx):
    card_list = [["name", "id"]]
    opts = []
    for x in card_list:
        if x[0].startswith(ctx.value.lower()) or x[1].startswith(ctx.value.lower()):
            opts.append(discord.OptionChoice(name=f"{x[0]} ({x[1]})", value=x[1]))
    print(opts)
    return opts```
all 3 times it prints an OptionChoice object
sage tendon
#

and how do you pass the autocomplete to the option

upper hearth
#

@discord.option("card", autocomplete=discord.utils.basic_autocomplete(card_searcher), required=False)

sage tendon
#

yea, guess what basic_autocomplete does

upper hearth
#

oh

#

didnt think of that

sage tendon
upper hearth
#

oh yeah i copied it from the example thats why

#

whats the type of autocomplete that doesnt od that then

sage tendon
#

nothing

#

just pass your function

upper hearth
#

ohhh

#

yes works now

#

thank you!

sage tendon
#

np

violet star
#
import os
import dotenv
from discord.ext import commands

dotenv.load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')

bot = commands.Bot()


@bot.command(description="Sends the bot's latency.") # this decorator makes a slash command
async def ping(ctx): # a slash command will be created with the name "ping"
    await ctx.respond(f"Pong! Latency is {bot.latency}")

@bot.event
async def on_ready():
    print(f"Logged in as {bot.user} (ID: {bot.user.id})")
    await bot.sync_commands()
    print('Bot is ready')


bot.run(TOKEN)```

i  am way too sleepy/stupid for this

issue: slash commands not showing
#

even if i have a mutual server with the bot

lofty parcel
#

And you don't use sync_commands in on_ready

#

The library already syncs commands in a separate event

#

You don't have to do it yourself

#

.tag client

sly karmaBOT
#
discord.Client # just for events
discord.Bot # events + slash/user/msg commands
commands.Bot # above + prefixed commands
bridge.Bot # above + bridge commands (application commands and text commands in one)
little cobalt
#

Im way to slow to write stuff at my phone.. xd

lofty parcel
#

Am on mobile too lolz

little cobalt
#

Uff

#

Time to sleep at 01:12

violet star
#

thanks

#

now it only shows in servers, im tryna make it work w/ user apps

#

my bad for not specifying

lofty parcel
#

You have to set contexts and integration types for user apps

violet star
#

aight bet

#

thx for putting up with stupid people's bullshit, appreciate people like you

wheat tiger
#

When will the new components be added?

lapis dock
#

Can't remember if you have asked before but they are available in the PR. Which I think is done so hopefully it gets merged and released soon. /Tag cv2 for more info

sly karmaBOT
#

Components V2 are under development in pycord and aren't yet included in the official releases on PyPI or the master GitHub branch. However, you can access the features now by installing directly from the pull request #2707. To do this, use the following command: pip install git+https://github.com/Pycord-Development/pycord.git@refs/pull/2707/head Please be aware that this is a development version and may contain bugs, feel free to report them by adding a comment to the pull request.

limber wagonBOT
#
Categories (7)

bot, howto, application_commands, embed, a, orjson, vps

wheat tiger
#

@fresh sierra

#

Have u every used docker to run ur bot?

#

(Which uses tortoise-orm and connects to DB)

#

When I run bot locally it run as expected

#

but inside docker container it throws this error (while trying to connect to postgresql DB)

[Errno 101] Network is unreachable
#

If I remove the connection to DB code, bot starts

fresh sierra
fresh sierra
wheat tiger
#

afaik it accepts from all connection

wheat tiger
#

@fresh sierra This works

#

2nd one

#

my vm was using ipv4

#

but why it wasn't a prob in localhost??

fresh sierra
wheat tiger
#

transaction pooler works

fresh sierra
#

Im using Maria db and pretty nice

wheat tiger
#

not direct conn

sage tendon
#

only ipv6 is wild

wheat tiger
#

but

#

direct connection works as expected in nodejs

#

drizzle orm

#

but issues in asyncpg, tortoise orm

wheat tiger
#

running directly like uv run main.py works

fresh sierra
wheat tiger
wheat tiger
echo wraith
#

@wheat tiger

wheat tiger
echo wraith
#

u using supabase or sms ?

wheat tiger
wheat tiger
echo wraith
#

how do you run your db ?

#

cuz your bot aint on the same network

#

probably thats the problem

wheat tiger
echo wraith
wheat tiger
wheat tiger
#

this is where issue lies

echo wraith
#

where are you running your database

#

like

#

launching the postgres thing

#

not in python

wheat tiger
echo wraith
#

on supabase ?!

#

like the cloud one ?

wheat tiger
#

not self hosted

echo wraith
#

ooooh

#

probably cuz ipv6 shit

echo wraith
wheat tiger
echo wraith
#

wdym this works

#

does it work on your local machine ?

#

that's what you mean ?

wheat tiger
wheat tiger
#

one pooler

#

other direct one

echo wraith
#

yeah no I got that

wheat tiger
#

pooler one only works in supabase, direct one won't
But that's not the issue in local machine

echo wraith
#

and wha about the "Session pooler" one

wheat tiger
wheat tiger
echo wraith
#

cool

wheat tiger
#

but why

echo wraith
#

wdym sucks

#

no

wheat tiger
#

also in docker only

echo wraith
#

you're a discord bot

wheat tiger
echo wraith
#

you aren't 10k discord bots

#

sessions are fine if you don't have many

wheat tiger
lapis dock
#

Isnt pooled connections needed for async applications anyways?

echo wraith
#

litterally

wheat tiger
#

(both on docker and locally)

echo wraith
#

idk but now it works

#

and so we don't touch it

wheat tiger
#

idk what's the issue in python

echo wraith
#

because

#

your pc got an ipv6 and iv4

#

and your vm just ipv4

#

there's no issue in python

wheat tiger
echo wraith
#

what's your os

wheat tiger
echo wraith
#

I think docker has some shit that disables ipv6 too

#

try doing ts

wheat tiger
#

in nodejs everything works without any issue

echo wraith
#

then idk

#

use discord.js

frail basin
#

why not just run the db locally

#

inside the docker compose

echo wraith
#

is there a reason why you using supabase

frail basin
#

isnt supabase just postgres?

echo wraith
#

or just the ui

echo wraith
wheat tiger
frail basin
wheat tiger
#

I would've said no and used local postgres if I was before 2 yrs

#

but

#

after webdev since 2 - 3yrs

#

mad for ui 💀

wheat tiger
echo wraith
#
  1. I do self host supabase, it's hella hard but I did it 🎉 and even did it in docker swarm
  2. If you want a ui for postgres just use nocodb
wheat tiger
lapis dock
#

PGAdmin 💪 (Pretty sure this does not apply to this situation)

echo wraith
#

Also isn't it called adminer

lapis dock
wheat tiger
#

also for every supported sql flavour

errant trout
#

i personally like dbeaver

#

but eh desktop tool

echo wraith
#

You should try this

echo wraith
#

I also like beekeeper studio

#

But both are apps not webuis

echo wraith
wheat tiger
echo wraith
wheat tiger
#

Also this

#

schema visualizer

echo wraith
#

Oh

#

Wait

#

That thing

wheat tiger
echo wraith
#

Database.build

#

By supabase

#

Is cool

wheat tiger
#

supabase works

#

but for production

#

I prefer self host

#

for testing and all it comes handy fast dev

#

How bad it can be if u use raw .json file as storage?

echo wraith
#

Idk I stopped using supa one year ago to go to standalone postgres

echo wraith
#

.tag nojson

sly karmaBOT
#

JSON is a convenient and easy-to-read data storage protocol that's widely accepted by most programming languages. However, we caution against its use for storing and retrieving data in an asynchronous environment like a Discord bot. Don’t use json!

  • It's a file-based data storage, which makes it vulnerable to race conditions
  • You'll need to implement your own synchronization primitives to avoid corrupting data
  • If you're not careful, you could accidentally wipe your entire JSON file.

Solution? Use a database. Recommended schema are SQLite, PostgreSQL, and MongoDB.

  • Async libraries exist on pypi for each of these
    sqlite - aiosqlite
    postgresql - asyncpg
    mongodb - motor
  • Databases organize your data into tables, and are fast at inserting, retrieving, and removing records
  • You can impose uniqueness constraints to ensure against duplication
  • The Python libraries enforce synchronization for you
  • The query language is intuitive, you can get running with simple queries in just a few hours!
little cobalt
echo wraith
little cobalt
echo wraith
#

pyon when

wheat tiger
little cobalt
#

I used json for 2 years as a DB so

wheat tiger
#

and proj was 4-5yo, all other stuffs were updated but json storage was as it is

#

last week updated to db 🤓

wheat tiger
echo wraith
#

Guys i've been making discord bots for less than 3 years

#

and I used txt files for like 2 months

wheat tiger
#

this is more horrible

echo wraith
#

and json never actually I went straight from txt to sqlite

echo wraith
#

and I had like 40 to store

#

so 40 files with inside of them one value per line

#

well key-list pair

wheat tiger
#

will tell to my friends abt this new idea

echo wraith
#

ship fast and break things they say ?

wheat tiger
#

"why not txt files?"

echo wraith
#

oh noooooo

#

nooooo txt files

#

noooooo

#

Anywaysss

#

physics exam tomorroorw

#

gtg study

wheat tiger
fresh sierra
wheat tiger
#

u can check

fresh sierra
wheat tiger
wheat tiger
#

Is there any way I can contrib my bot as a example bot for pycord?

sage tendon
#

not really a thing

fresh sierra
fresh sierra
#

is there any way to edit discord.Interaction (to basically set the interaction.user to member (always true in my usecase since my commands and only be triggered in guild)
goal would be to not have to put everytime MyInteraction, but be able to continue to use discord.Interaction

something like
discord.Interaction = MyInteraction

sage tendon
#

is interaction.user the user object always?

fresh sierra
#

and None when discord is pinging the interaction (but according to nelo we dont have to deal with that its handle at the bse)

sage tendon
#

so what's the issue at hand

#

if your command is always in a guild it'll always be a member object

fresh sierra
#

like this in a way

sage tendon
#

just make a type alias

#

if it's typed as User | Member

fresh sierra
#

goal would be to not have to put everytime MyInteraction, but be able to continue to use discord.Interaction

#

(idk if its even possible)

#

because having to change every discord.Interaction gonna be tough

sage tendon
#

I never said to change it

sage tendon
sage tendon
fresh sierra
#

what do you mean ?

#

i dont get how to do that if you prefer for i dont have to change the discord.Interaction

sage tendon
#

just type it as User | Member it's not that big of a deal

fresh sierra
#

do you mean like this ?
async def button_callback(self, interaction: discord.Interaction):
user: cast(discord.Member, interaction.user)

#

(my goal would be to change it once in a file and then inside my whole workspace interaction.user would appear as member

sage tendon
#

Not really

#

I'm just saying leave it as is

#

you can't really do what you're trying without a custom subclass

grizzled loom
fresh sierra
#

Items should be typed item[View]

#

Which was not the case hee

grizzled loom
#

alright

echo wraith
#

Idk if this is what this is about but I might as well share

valid panther
#

I am testing the pycord.i18n library and as far as I can see it can only do single level traversal without nested dictionaries so I have created a def to add this feature. Do you think this is a good idea or the library already has a def for it? I had also thought of implementing reddis to store the languages, but I don't know if it would be applicable.

#

floosh thxx for all

fresh sierra
valid panther
fresh sierra
valid panther
lapis dock
#

Doru is not super active because they live in a place that banned discord, unfortunately.

sage tendon
#

vpn?

lapis dock
#

They are sometimes on. But their activity did have a noticeable dip after the ban

cursive swallow
#

the vpn always gives me problems

sage tendon
#

try proton

eternal kite
#

is it possible to add select option in modal?

lapis dock
#

No :(

silk spire
#

Imagine blobpain

little cobalt
eternal kite
lapis dock
#

Discord limitation

chrome plover
#

Could someone help me with this?

Persistent view error

Traceback (most recent call last):
  File "C:\Users\zi\Downloads\ProjectValor-main\ProjectValor-main\venv\lib\site-packages\discord\cog.py", line 796, in _load_from_module_spec
    setup(self)
  File "C:\Users\zi\Downloads\ProjectValor-main\ProjectValor-main\bot_files\cogs\Giveaway.py", line 110, in setup
    bot.add_view(GiveawayView())
  File "C:\Users\zi\Downloads\ProjectValor-main\ProjectValor-main\bot_files\cogs\Giveaway.py", line 14, in __init__
    super().__init__(timeout=None)
  File "C:\Users\zi\Downloads\ProjectValor-main\ProjectValor-main\venv\lib\site-packages\discord\ui\view.py", line 186, in __init__
    loop = asyncio.get_running_loop()
RuntimeError: no running event loop

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\zi\Downloads\ProjectValor-main\ProjectValor-main\bot_files\valor.py", line 82, in <module>
    client.load_extension(ext)
  File "C:\Users\zi\Downloads\ProjectValor-main\ProjectValor-main\venv\lib\site-packages\discord\cog.py", line 918, in load_extension
    self._load_from_module_spec(spec, name)
  File "C:\Users\zi\Downloads\ProjectValor-main\ProjectValor-main\venv\lib\site-packages\discord\cog.py", line 801, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.errors.ExtensionFailed: Extension 'bot_files.cogs.Giveaway' raised an error: RuntimeError: no running event loop

relevant cog code:-

def setup(bot):
    bot.add_cog(Giveaway(bot))
    bot.add_view(GiveawayView())
little cobalt
#

Why did you add the view at the setup of a cog?

errant trout
real glacier
#

hey guys! weird question, why does accessory required in discord.ui.Section()

#

like always i mean

frail basin
real glacier
#

ThinkO_O o

silk spire
#

Because that's what a section is

up to
three Button/Thumbnail
TextDisplays

#

Use a TextDisplay + Separator if you don't want an accessory

real glacier
#

The 'content' field cannot be used when using MessageFlags.IS_COMPONENTS_V2 oh wow cat hope it was a bug because

silk spire
#

Nah you can only send the new components with the cv2 flag

#

Use a TextDisplay

real glacier
round heart
eternal kite
#

is there a maximum number of commands a bot can have?

shell radish
#

?tag cmd-limits

limber wagonBOT
#

You can have 100 commands, and each command can have up to 25 sub-command groups. Each sub-command group can have up to 25 sub-commands.

100 x 25 x 25 = 62,500

Of course, "slash commands can have a maximum of 8000 characters for combined name, description, and value properties for each command and its subcommands and groups", so you're not likely to hit that 62.5k command limit

This can be doubled again with guild commands. (125,000)

sage tendon
#

i worry about that question

fresh sierra
#

@wheat tiger how do you do to see outdated lib with uv ?

#

And to update branch too

#

Because when I do uv sync it doesn’t update the branch to the last est

eternal kite
#

The specified component exceeds the maximum width what does it mean? is the label too long?

sage tendon
#

shorten it and see if it works

lapis dock
agile oar
#

Anyone elses bots continually reconnecting to the API resulting in a 429 error?

discord.errors.HTTPException: 429 Too Many Requests (error code: 30034): Max number of daily application command creates has been reached (200)

lapis dock
#

Are you syncing manually?

agile oar
#

No

#

It syncs automatically when the bot reconnects

#

So it must be disconnecting and reconnecting repeatedly. But the network is stable..

lapis dock
#

Can you make sure you don't have multiple instances of the bot running

lapis dock
agile oar
#

Good shout

#

Let me check that

agile oar
#

Thank you

#

Thankfully this was my testing bot, so no customers bots have been affected kek

lapis dock
#

Yup the 2 instances must have been fighting over what commands should be registered.

real glacier
#

hey guys! is it possible to make paginator with the new ui component like containers? instead of embeds=[]

#

i feel like it too much work

echo wraith
real glacier
#

cry thats okay as long as its possible

#

thanks!

echo wraith
#

You should try and see

eternal kite
#

uh so.. my bot is starting to become slower due to the large amount of users, is there any action i can take to reduce the amount of lag in the bot?

#

about 50 commands are used every second

fresh sierra
#

limit usage of recursive command

eternal kite
#

it definitely is

#

i dont use recursive

#

but maybe quite a lot of for loops and while loops

#

but the commands are all async

fresh sierra
#

try to have a vps in the us next to discord

eternal kite
#

my hosting server is in the us

fresh sierra
fresh sierra
fresh sierra
#

if your bot is open source i can take a look

eternal kite
fresh sierra
eternal kite
fresh sierra
#

if you have 20ping or 300 that will not be the same

fresh sierra
#

even tho its inside an async function

#

.tag rie

sly karmaBOT
#

You can run blocking code (such as PIL/Pillow) in an executor to run it in a separate thread:

def my_blocking_func(*args):
    ...

@bot.command()
async def test_command(ctx):
    ret = await bot.loop.run_in_executor(None, my_blocking_func, 'put', 'args', 'here')

See the python documentation for more info.

fresh sierra
#

you should do like this

eternal kite
fresh sierra
eternal kite
#

i see

fresh sierra
#

which can be pillow according to what you told me

eternal kite
#

yup for loops with image opening

fresh sierra
#

for image opening you should use aiofiles its async

eternal kite
#

so how can i create an asynchronous for loops

echo wraith
#

Maybe run a profiler on your code

eternal kite
eternal kite
eternal kite
echo wraith
#

try this

fresh sierra
echo wraith
fresh sierra
echo wraith
#

you can open your file async and pass bytes into pillow

fresh sierra
#

and for aiofiles you can use it the same way as normal file just add await

eternal kite
#

so my code is like

for image in image_list:
     img = Image.open(f"{image}.png")
     bg.paste(img, pos)
#

just an example

fresh sierra
#

forexample

eternal kite
eternal kite
#

it prevents memory leak right?

fresh sierra
#

it prevent blocking code by running it inside a separate threads

eternal kite
# fresh sierra nope

alr so instead of running it in an executor, what if i just make the whole function async

fresh sierra
#

so you will have to use rie

eternal kite
#

oh

#

alr got it thx

fresh sierra
#

putting code inside an async function doesnt make it async

eternal kite
#

saved me a bunch of time reading docs sadcatthumbsup

lapis dock
brazen mango
#

Hi, I have just upgraded to Python 3.13 and now Pycord raises an error every time I try to run my bot. Should I revert my venv to 3.12? When will 3.13 be supported?

lapis dock
#

Not sure if 2.7 will fully support 3.13 but the core problem can be solved by...

sly karmaBOT
#

Pycord 2.6.1 may work with Python 3.13, but it is not officially supported and can cause various issues. Until Pycord 2.7 includes official support for Python 3.13, it is recommended to use a previous version.

For voice features in Pycord versions before 2.7, you might need to run pip install audioop-lts. Some users have reported issues with voice features when using Python 3.13, so ensure that you clear the __pycache__ and .pyc files before running your bot.

sage tendon
#

Would be genuinely sad if it didn't

#

Especially because it only affects voice, which I'll take a wild guess the vast majority of people never use

brazen mango
#

I'm not using voice features and get an error.

sage tendon
#

I never said you do

lapis dock
#

Yeah, you can also use master to fix that issue

brazen mango
#

However, I've noticed that the error does not occur the first time I run the bot, which is explained by the __pycache__ thing.

brazen mango
lapis dock
sage tendon
#

2.8??

lapis dock
#

Mobile typing

sage tendon
#

ah

#

I'm using 3.13 on my dev env as well as my server

#

haven't noticed any issues so far

lapis dock
brazen mango
#

it happens as soon as I import discord

#

maybe a bug with that PR, idk

sage tendon
#

can you send the fork link

brazen mango
#

anyways it only happens in 3.13

sage tendon
#

i cant find nelos fork rn

sly karmaBOT
#

Components V2 are under development in pycord and aren't yet included in the official releases on PyPI or the master GitHub branch. However, you can access the features now by installing directly from the pull request #2707. To do this, use the following command: pip install git+https://github.com/Pycord-Development/pycord.git@refs/pull/2707/head Please be aware that this is a development version and may contain bugs, feel free to report them by adding a comment to the pull request.

sage tendon
#

15 commits behind

brazen mango
#

was it fixed less than a week ago? that would explain it.

sage tendon
#

no clue

#

either way just reset your venv completely

#

cache is a bitch

lapis dock
brazen mango
#

ok, so maybe I just messed up the cache
lemme retry

#

I wonder why Python doesn't recreate the Pycache on venv change. Shouldn't that be the whole point of virtual environments? Keeping installations separate?

sage tendon
#

the point of venvs is to have a set of packages specifically for one project

brazen mango
#

Anyways now it works, thanks for your advice!

sage tendon
#

np

real glacier
#

quick question! does topgg still works with py-cord? or does their sdk even working

lapis dock
#

You might have to use the master branch so that it does not automatically install discord.py I assume it would still work tho

#

That is probably a better question for them

real glacier
#

ok thank you!

echo wraith
#

Their library is garbage just do it manually

sage tendon
#

didnt they have some issue some time ago?

real glacier
sage tendon
#

what does that even mean

real glacier
#

i mean

little cobalt
#

?

errant trout
#

and we can't really help much

sage tendon
#

legit find it silly af that a simple website like topgg needs a wholeass SDK

#

especially since their API isnt all that big

errant trout
#

from what i can tell only their rust lib is official, the rest are community efforts

real glacier
errant trout
#

(we can see how that ended up)

sage tendon
#

they have 2 endpoints and like 20 possible requests

#

there is no fucking need for an SDK and libraries in 50000 languages

errant trout
#

well yeah but people will make them regardless

sage tendon
#

sorry, 8 possible requests

#

incredible

little cobalt
errant trout
sage tendon
#

yea i heavily agree, their API is stupid simple

errant trout
#

oh i think they also have an event implementation for listening to vote events

real glacier
errant trout
#

allgood

sage tendon
errant trout
sage tendon
#

oh its there

real glacier
sage tendon
#

just do it manually

real glacier
#

kk!

real glacier
#

hi guys its working with aiohttp! thanks alot :DD

errant trout
#

allgood

sinful juniper
#

Why is my code always being underlined here? It tells me it's probably because of pylance... Which packages do I need in Visual Studio Code to work with Python and program bots?
I have installed these:

  • isort
  • Pylance
  • Python
  • Python Debugger
sage tendon
#

because that syntax is semi abusing how python works

#

the proper way, imo, is to use the decorator

#

also, required=True is the default, you dont need to pass it

sinful juniper
sinful juniper
lapis dock
# sage tendon didnt they have some issue some time ago?

Well someone here was trying to use it and together we found out that a maintainer for a different top.gg repo had perms for they python repo. They got hacked and someone committed malware to the master branch. Went unnoticed for at least a few days until we brought it up.

sage tendon
#

ah yea that

sinful juniper
sage tendon
#

use the decorator

#

but you dont have to pass the type if its str, and you can just pass it positionally, no need for type=

#

otherwise its all the same kwargs

echo wraith
#

.rtfm discord.option

echo wraith
#

Lowercase

eternal kite
#

sending modal keeps raising unknown interaction error for specific users?

#

im pretty sure it's discord's issue tho

#

it works for some users and not for the others

silk spire
#

Are you always responding to the interaction the correct way?

little cobalt
echo wraith
#

.tag paste

sly karmaBOT
#

Please copy and paste your code here. This makes it easier for everyone helping you.

eternal kite
#

this unknown interaction persisted for nearly a month

eternal kite
silk spire
#

You can use ctx.send_modal as a shortcut, but weird

eternal kite
#

hmm

#

i think it has to do with the bot.check

#

I'll debug it when im home

#

but what exactly triggers the error?

#

unknown interaction

silk spire
#

Not responding within 3 seconds

torn barn
#

responding after 3 seconds

silk spire
#

Which means the interaction token is invalidated

silk spire
red crypt
#

has anything changed in regards to bots and thread channels?

i host a middleman bot, and we primarily use threads over channels, mostly so that we don’t see all the channels and they’re hidden in their own little category.

recently the bot just stopped being able to make any threads whatsoever

i haven’t been home to be able to check any error logs, i tried remotely using termius but pm2 was showing no activity in its list, and it was already hard to manoeuvre the actual remote pc off my phone, the bot other than threads works just fine, all commands work no issues there

when running the bot, to create the thread you click a button, the bot will create the thread but never add the user nor send messages to said thread

echo wraith
#

not that I know

sage tendon
#

err just as a sidenote you can hide channels you dont wanna see since quite a long time now

wheat tiger
#

@fresh sierra U can do uv lock -U && uv sync for that

cerulean laurel
#

hi so is there a way to show all categorys of a guild in an option for the user aand pass the id of the chosen category

errant trout
real glacier
#

how to add a Button() at the right side between the TextDisplay() in cv2?

cerulean laurel
sage tendon
#

show more of it

errant trout
#

remove type=, input type is always first argument

cerulean laurel
#

oh ok

sage tendon
#

shouldnt it still work tho?

#

or is it pos only

errant trout
#

the arg is called input_type anyway, can't remember if it's forced pos

sage tendon
#

a

sage tendon
#

typehint cringe

real glacier
#

or *item

cerulean laurel
real glacier
errant trout
errant trout
real glacier
#

it looks weird on mobile!

#

at least not on pc

errant trout
#

mobile you kinda just have to deal with it, they tried their best

real glacier
#

it kinda triggered me but ok, all good!

cerulean laurel
errant trout
#

yep

cerulean laurel
#

ok

cerulean laurel
#

in this code is there a way to send not the name of the role or user for example but to mention them?

@discord.slash_command(name="test")
async def test(self, ctx, testinput, category = Option(discord.CategoryChannel), role = Option(discord.Role), member = Option(discord.User)):
    await ctx.respond(f"{testinput}\n{category}\n{role}\n{member}")
lofty parcel
#

Also god, what's that typehinting