#Basic Pycord Help

1 messages · Page 80 of 1

frail basin
#

my main concern is messing with the cache

#

I would only be using this for reply generation and not for any logic

echo wraith
#

Probably would be easier to use some dataclass

errant trout
#

this technically works and won't mess with cache, but i'm not sure why you're doing this at all

frail basin
#

I want to test my reply generator's placeholders, without having to actually run the commands/buttons/etc necessary to trigger it normally.

sage tendon
#

no idea if copy deep copies but you probably should if it doesn't

frail basin
#

It just calls __new__ and manually sets attributes

errant trout
#

the builtin User._copy just creates a new class and copies the attrs while bypassing __init__ and cache

#

i'd personally opt for making your own lighter class that only has what you need.... but if your current method works then eh wtv go for it

frail basin
#

I dont know what the end user will need in terms of properties and all

#

so I want to provide everything

errant trout
#

well yeah but if that "everything" is your own bot's attributes then it's kinda useless

#

also you may need to be careful since bot.user is ClientUser, not User

sage tendon
#

are you making a mocking framework or

errant trout
#

sounds like a ticket system or something to me but eh vague guess

frail basin
errant trout
#

bruh

frail basin
#

Dw this is a private commission not a public thing

errant trout
#

fair enough ig

#

why can't you just use the user's real object?

frail basin
#

ffs

#

thats true

sage tendon
#

lol

frail basin
#

Ig I could get most things from the interaction

#

except threads

errant trout
#

interaction.user should have everything you need

#

getting threads is a different matter depending on what you're looking for

#

considering your original goal

without having to actually run the commands/buttons/etc necessary to trigger it normally
if not interaction.user, just get_or_fetch_user on client

frail basin
errant trout
#

if you really want yeah that works

frail basin
#

I assume interaction.user would be User in dms and Member in guilds?

errant trout
#

yea

frail basin
#

is it ever None if called from a guild?

#

actually is it ever None?

errant trout
#

it's typed as None as technically interactions without a user do exist

#

but in practical library usage, it will never be None

#

(i.e. so long as a user triggered the interaction, which should be 100% of your command/button/ui interactions, it will exist)

balmy dome
#

Why, when using await interaction.response.edit_message(view=interaction.view) with an edited view (replacing TextDisplay via id), does the original message remain visually unchanged, even though it says that the change was successful below the message?

errant trout
balmy dome
errant trout
balmy dome
# errant trout Can you show how you actually edited it
view = View(*interaction.view.children)

new_task = _Task(...)
            
section = _from_task_data_to_sections(
    interaction.user, [new_task,], False, False)
            
view.get_item(self.section_id).items = section[0].items
view.get_item(self.section_id).accessory = section[0].accessory

await interaction.response.edit_message(view=view)
errant trout
#

Are you sure those are distinct items? If you're not seeing edits it sounds to me like get_item(section_id) and section[0] are identical

balmy dome
sage tendon
#

just for making triple sure, can you edit the section to just contain a single manually created TextDisplay, and after that, get the section items and print them?

errant trout
#

What if you clear the original section.items, then iterate through your new section.items and add_item

#

(I should implement replace_items or something...)

balmy dome
valid panther
#

When I enter the command, the emoji appears, but when someone else enters it, it doesn't appear.

sage tendon
#

read the message you replied to

#

that looks like cv2

valid panther
sage tendon
#

yes

#

that is indeed very wonky
either its a bug or a weird intended behavior by discord
the reason, i think, is because its a user app and since the author (=the user who sends the command) doesnt have that emoji anywhere, it doesnt work

valid panther
#

I'm going to try with an emoji that is in the bot itself and not on a server.

sage tendon
#

yea thatll work for sure

little cobalt
#

or something like that?

valid panther
#

I didn't get it floosh

little cobalt
#

mhm

valid panther
#

Thank you very much, sorry for the inconvenience

sage tendon
lapis dock
#

For consistent emoji behavior in user apps you have to use app emojis.

sage tendon
#

still feels like a bug

valid panther
#

Is there a way to call this section to get the emojis dynamically? or only copy id an format ?

raw beacon
sage tendon
#

if you use the master branch, it's in bot.emojis

sage tendon
valid panther
#

stable version is 2.6.1?

sage tendon
#

yes

valid panther
#

swagcat is from the next update?

sage tendon
#

yea

#

thats why i said "if you use the master branch" lol

valid panther
#

floosh that true

valid panther
#

Is there a date for 2.7?

sage tendon
#

no

valid panther
sage tendon
#

ive been using the master branch for a few weeks now

#

no issues so far

wheat tiger
#

no issues

flat apex
#

Is there a clean way to know if a user dismissed an ephemeral message? My on_timeout will reply to a message that's already been dismissed. I can't think of anything other than just throwing a method that'll error out on something that's been deleted and wrapping that in a try/except, but I wanna check if there's a proper way first lol

errant trout
#

dismissing doesn't even count as a delete, it just hides it on that client

sage tendon
#

if youre trying to handle buttons, just disable the view on timeout

flat apex
sage tendon
#

if they cant press the button nothing can go wrong Shrug_3

flat apex
#

discord hurts me sometimes

#

all the time* really

#

Eh I guess since it's not "Deleted" I can still edit the embed to say it's timed out, I guess that works

#

It'll just edit a ghost message if they dismiss it since timeout still fires

sage tendon
#

but you are editing the message to make the button be disabled right

loud kayak
#

how do i make a discord.Option for a slash command but include forum channels in the options?

#

like users can put a forum channel

errant trout
#

list of discord.ChannelType enum

loud kayak
#

oh ok

loud kayak
# errant trout list of `discord.ChannelType` enum

i did this but it didnt make the forum channels show up

channel: Option(discord.TextChannel, "The channel the ad was deleted in", required=True, channel_types=[discord.ChannelType.text, discord.ChannelType.forum])```
errant trout
#

Did you reload your client

#

(And presumably restart your bot)

loud kayak
sage tendon
#

you don't need required=True btw

lapis dock
#

Toothy, you would not have been happy with krittick, they preferred everything to be explicit

sage tendon
#

Shrug_3 just wanna let them know
what they do with it is their problem

flat apex
loud kayak
#

how can i make it so a slash command option like discord.Option(discord.Attachment) only accepts pngs/jpgs (images)?

#

is there a built in ui check for it?

shell radish
#

no there isn't

loud kayak
#

oh ok

round heart
lofty vaultBOT
#

Reminder for @echo wraith

Reminder from YAGPDB

wtf

shadow bear
#

Hey, I've just done a fresh install with py-cord via pip install py-cord~=2.6, but I get this upon trying to start the new bot:

ModuleNotFoundError: No module named 'audioop'

I tried to install audioop but pip can't find a package with that name so im not sure what required dependency is being omitted

echo wraith
#

.tag audioop

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.

shadow bear
#

Oh didn't even realise I had 3.13 installed let alone was using it lmao

#

thanks

little cobalt
echo wraith
#

that does not rely on it anymore

little cobalt
#

Oh nice

tacit depot
#

I’m having an inconsistent issue with joining a voice channel. I’ll run my bot, it will connect to the voice channel, listen to audio and work correctly. I’ll then disconnect from the channel with a bot command that ends the connection. I’ll make a change to the bot or add a new command unrelated to the voice channel connection logic and restart the bot. Except the 2nd time I start it it hangs trying to connect to the voice channel and never succeeds. If I wait an hour or two and try again it works once again.

Any idea if there’s cleanup not happening, or I need to register the bot after changing it?

sage tendon
#

there's a voice change discord did a bit ago, 2.6.1 is affected, im not sure if its fixed on the master branch yet, but it sounds like that could be it
are you getting an error in the console

tacit depot
#

Sometimes ill get an error that says unclosed voice connection, but most of the time it just silently fails and continues until I get to the isconnected call which returns false

#

The bot will leave the voice channel from the users perspective but it won’t realize until it reaches the is connected function call

sage tendon
#

can you show it

tacit depot
#

Do you want the log snippet or a video of the whole flow from the discord client side as well?

sage tendon
#

just the traceback

tacit depot
#

Sure give me a few minutes

tacit depot
#

I’m not checking or printing any return code from the voice client object I get back from connect. I’ll check that as well for the reason it fails

#

Sorry for the delay in the trace back I’m at my day job and need to get back to my personal machine to test

echo wraith
#

.tag master

sly karmaBOT
#

pip install -U git+https://github.com/Pycord-Development/pycord
-# Note: The Master Branch May Have The Newest Features But It May Also Have More Bugs
The docs for the master branch: https://docs.pycord.dev/en/master/

tacit depot
#

Using the master branch:

Error occurred while decoding opus frame.
Error occurred while decoding opus frame.
Error occurred while decoding opus frame.
Error occurred while decoding opus frame.
Error occurred while decoding opus frame.
Error occurred while decoding opus frame.
Error occurred while decoding opus frame.
Error occurred while decoding opus frame.
Error occurred while decoding opus frame.
[00:46:43] Tolerant Alex: Subtitles by Subtitle WorkshopError occurred while decoding opus frame.
Error occurred while decoding opus frame.
Error occurred while decoding opus frame.
Error occurred while decoding opus frame.
little cobalt
#

What is opus frame??

tacit depot
#

Using 2.6.1:

[Guild xxxxxxxx] Voice connection established (no response_error property)
Registered user: Tolerant Alex (ID: xxxxxx)
Registered user: Grok Test Bot (ID: xxxxxx)
[Guild xxxxx] Transcription worker startedUnclosed connection
client_connection: Connection<ConnectionKey(host='c-sjc06-df8286f7.discord.media', port=443, is_ssl=True, ssl=True, proxy=None, proxy_auth=None, proxy_headers_hash=None)>
Unclosed connection
client_connection: Connection<ConnectionKey(host='c-sjc06-df8286f7.discord.media', port=443, is_ssl=True, ssl=True, proxy=None, proxy_auth=None, proxy_headers_hash=None)>
Unclosed connection
client_connection: Connection<ConnectionKey(host='c-sjc06-df8286f7.discord.media', port=443, is_ssl=True, ssl=True, proxy=None, proxy_auth=None, proxy_headers_hash=None)>
Unclosed connection
client_connection: Connection<ConnectionKey(host='c-sjc06-df8286f7.discord.media', port=443, is_ssl=True, ssl=True, proxy=None, proxy_auth=None, proxy_headers_hash=None)>
Unclosed connection
client_connection: Connection<ConnectionKey(host='c-sjc06-df8286f7.discord.media', port=443, is_ssl=True, ssl=True, proxy=None, proxy_auth=None, proxy_headers_hash=None)>


Ignoring exception in command join:
Traceback (most recent call last):
  File "/home/alex/discord/venv/lib/python3.11/site-packages/discord/commands/core.py", line 138, in wrapped
    ret = await coro(arg)
          ^^^^^^^^^^^^^^^
  File "/home/alex/discord/venv/lib/python3.11/site-packages/discord/commands/core.py", line 1082, in _invoke
    await self.callback(ctx, **kwargs)
  File "/home/alex/discord/discord_transcriber_bot.py", line 327, in join
    vc.start_recording(
  File "/home/alex/discord/venv/lib/python3.11/site-packages/discord/voice_client.py", line 777, in start_recording
    raise RecordingException("Not connected to voice channel.")
discord.sinks.errors.RecordingException: Not connected to voice channel.
tacit depot
lapis dock
errant trout
#

idk

lapis dock
#

github moment

little cobalt
lapis dock
tacit depot
#

This is my requirements.txt: git+https://github.com/Pycord-Development/pycord.git@master Is that correct?

little cobalt
#

.tag master

tacit depot
#

I'm not sure I follow, what pip command would you use to install .tag master?

#

Not git+https://github.com/Pycord-Development/pycord.git@refs/tags/master right?

lapis dock
#

I think you only need this
git+https://github.com/Pycord-Development/pycord
Just install that again, incase you were on an older commit

tacit depot
#

So it can join the channel correctly with that package, but it won't record any audio and gives me the same Error occurred while decoding opus frame. error

#

This is my sink:

class RealtimeTranscriptionSink(discord.sinks.WaveSink):
    def __init__(self, guild_id, *, filters=None):
        # Initialize parent WaveSink class
        super().__init__(filters=filters)

        self.guild_id = guild_id
        self.audio_queue = queue.Queue()
        transcription_queues[guild_id] = self.audio_queue
        self.user_buffers = {}  # Track audio per user

    @discord.sinks.Filters.container
    def write(self, data, user):
        """Called when Discord receives audio data"""
        # user parameter is actually a user_id (int), not a user object
        user_id = user

        # Create user audio data if doesn't exist
        if user_id not in self.audio_data:
            self.audio_data[user_id] = discord.sinks.AudioData(io.BytesIO())

        # Write to audio_data for this user
        self.audio_data[user_id].file.write(data)

        # Try to get username from user_id (will use ID as fallback)
        user_name = f"User-{user_id}"
        if user_id not in user_names:
            user_names[user_id] = user_name
        else:
            user_name = user_names[user_id]

        # Put audio data with user info into the queue
        self.audio_queue.put((data, user_id, user_name))

    def cleanup(self):
        """Called when recording stops"""
        # Signal the transcription thread to stop
        stop_flags[self.guild_id] = True

        # Call parent cleanup which handles format_audio
        super().cleanup()
lapis dock
#

I dont have time to look at it now sorry

tacit depot
#

No problem. Whenever you get the chance let me know if there’s any other info you need

torn light
#

My message_command can be used on any server, but I need to know that only authorized people use it.
The authorized people are all on the same server under the same role
How do I do this?

errant trout
torn light
#

Oh, I already found a way to do that.

   guild = bot.get_guild(756512042827120641)
   if guild is None:
      guild = await bot.fetch_guild(756512042827120641)

   member = await guild.fetch_member(inter.author.id)
   role = member.get_role(1297906376995246141)

   if role is None:
      return
errant trout
#

if that works then sure, but editing it in guild settings will also hide the command from people who don't have the role

lapis dock
#

If they are all in the same guild, register it as a guild command

silk spire
#

Why are we fetching the member

#

interaction.author has almost everything

#

Presences data is the only thing missing afaik

torn light
#

This command is intended for use within a guild, to be used in other guilds.

#

I'm not sure that a member will find a role if that member is not taken from a guild where that role is present.

sage tendon
silk spire
#

Ah missed that

#

But always try cache first with the method mentioned above

loud kayak
#

anyone know why importing from datetime import datetime then doing datetime.fromtimestamp produces an error that fromtimestamp or any other datetime thing doesn’t exist? randomly happening to me

sage tendon
#

just import datetime

quasi dune
#

Super basic question, I hope! Does every single item in a Components v2 persistent view need a custom_id or only the interactable ones? Also, I'm assuming the id property of the new component structures is the same as custom_id for the old ones? (Please correct me if I'm wrong ^.^)

errant trout
#

id is a new attribute on ALL items in views and modals

#

if you don't set it, discord will automatically increment it

#

both custom_id and id work in View.get_item and related functions

lapis dock
#

(because custom_id is a string and id is an int)

quasi dune
errant trout
#

basically, if you want to conveniently get an item at some point later on, setting id is useful

lapis dock
#

I think the id property could be useful for classifying data that other bots read. IE 400 is "my cool discord game" coin stats text displays or something

quasi dune
#

Ooh okay, that makes sense.

#

So just to confirm then, I'm getting this error when trying to create a persistent view:
ValueError: View is not persistent. Items need to have a custom_id set and View must have no timeout
The view definitely has no timeout, so... which items need a custom_id again? Allegro_love

torn barn
#

all interactible items need custom_ids

errant trout
#

ah yea, just button and select

torn barn
#

ie buttons & selects

quasi dune
#

Sick, thank youuuu

#

❤️

#

I should really try to lurk in here and help people out more often, you all have definitely made me less fearful of posting questions and problems.

quasi dune
tardy bluff
#

Why is this getting "unknown interaction integration"?

@bot.command(description="test")
async def test(ctx):
    await ctx.respond("hello i'm an hidden message", ephemeral=True)
sage tendon
#

does it take 3 seconds to show that? (roughly)

tardy bluff
#

No, it shows instantly

#

And there aren't any errors in stdout

sage tendon
#

stop the bot and run the command again

tardy bluff
sage tendon
#

restart your client

tardy bluff
#

Fixed it, it was because the "prod" version was still running too

sage tendon
#

yea i guessed so lol

waxen briar
#

how can you edit ephemeral msgs?

frail basin
waxen briar
frail basin
#

try Interaction.delete_original_response

waxen briar
#

nvm ive got it

#

ty tho

steep cliff
#

What are the minimum specs an average discord bot needs to run on a vps?

errant trout
#

How many servers/members does your bot have

steep cliff
#

Like 3 servers with 500members each

#

I guess the most intense task is adding 500members to a thread

sage tendon
#

isn't it easier to either ping them or make a channel

steep cliff
#

Im pinging them (in edit to make sure they don’t actually get pinged), however can’t ping the role as that won’t add members to a thread if the role has more than 100 members and a channel doesn’t make sense for what we’re doing.

#

Question is whether 1GB is enough or if I should go for 2 just to be safe?

steep cliff
#

Kinda not what I asked tbh

lofty parcel
steep cliff
#

Thx :)

#

Is it similar in size (server/member wise)?

lofty parcel
#

Its handles 1 server of 500 members plus a web server

errant trout
steep cliff
#

Thx :))))

sage tendon
#

my bot uses 71mb with 300 members @ 1 server

#

so, yea, lol

fickle salmon
#

I'm clearly doing something stupid

Aug 30 23:26:37 bots FPGLBot[425619]: In data.components.1.components.0.accessory: This field is required```
```py
class QueueView(View):
    session_cog = None
    session = None
    container = None

    def __init__(self, session_cog, session=None, container=None):
        super().__init__(timeout=None)
        self.session_cog = session_cog
        self.session = session
        self.container = container
        if container:
            self.add_item(container)
lapis dock
#

You are required to have an accessory in sections, I assume you have a section in your container

fickle salmon
#

am I required to have a section?

lapis dock
#

no

fickle salmon
#
title = TextDisplay(title)
queue_str = TextDisplay(queue_str)
footer = TextDisplay(
    "-# Please skip anyone who has ⏭️ next to their name or is currently helping someone else"
)
section = Section(title, queue_str, footer)
container = Container(section, color=self.bot.color)
# container = discord.Embed(
#     title=title, description=queue_str, color=self.bot.color
# ).set_footer(text=footer)
return container```
lapis dock
#

You can just add those 3 text displays to the container

fickle salmon
#

like this? container = Container(title, queue_str, footer, color=self.bot.color)

lapis dock
#

(Also you can put them all in one text display to save componenets)

fickle salmon
#

can I make this without sections?

lapis dock
#

no, you need the section to get the image inline with the text. You could not use a section and put the image below or above tho

fickle salmon
#

I guess I'm confused on what a section is anyway. it's not an option in discord.builders? or is that what the little thing on the right is, is that adding a section?

#

sorry, ignore the duck picture.

#

forgot we added that when testing

lofty parcel
#

Its be cool to create a visual thing

errant trout
lapis dock
#

I think discohook hasa visual builder

errant trout
#

Section is just text with thumbnail/button on the right

lofty parcel
#

Oh

#

Well that simplifies it

#

Lmao

errant trout
#

(But may be expanded in future)

fickle salmon
#

so if I don't want button/thumbnail on the right I don't need section

errant trout
#

Yes

#

Rather, section requires both text and accessory

fickle salmon
#

there we go, just need the buttons now

errant trout
#

Oh right I wanted to add an arg to decorators to let them be added at the end

fickle salmon
#

I can do this right?

skip_button = Button(
    label="Skip", style=discord.ButtonStyle.grey, custom_id="queue_view:skip"
)
skip_button.callback = self.skip
container.add_item(skip_button)

async def skip(self, button: Button, interaction: discord.Interaction):
    await self.session_cog._skip(None, interaction.user, self.session)```
#

I'm getting this: Aug 30 23:54:16 bots FPGLBot[433472]: Ignoring exception in view <QueueView timeout=None children=1> for item <Button style=<ButtonStyle.secondary: 2> url=None disabled=False label='Skip' emoji=None sku_id=None row=None custom_id='queue_view:skip' id=5>: Aug 30 23:54:16 bots FPGLBot[433472]: Traceback (most recent call last): Aug 30 23:54:16 bots FPGLBot[433472]: File "/home/dev/.venv/stage_fpgl_bot/lib/python3.11/site-packages/discord/ui/view.py", line 556, in _scheduled_task Aug 30 23:54:16 bots FPGLBot[433472]: await item.callback(interaction) Aug 30 23:54:16 bots FPGLBot[433472]: ^^^^^^^^^^^^^^^^^^^^^^^^^^ Aug 30 23:54:16 bots FPGLBot[433472]: TypeError: QueueView.skip() missing 1 required positional argument: 'interaction'

sage tendon
#

your callback has a wrong set of args

fickle salmon
#

callback has self, button, and interaction

sage tendon
#

remove button

#

self is the button if you set it like that

fickle salmon
#

gotcha

sage tendon
#

also idk if you know but you can stuff all the components into the container init call

#

Container(
section(
textdisplay()
)
)
like this sorta

#

imo a really good way to visualise it in code

obsidian glacier
#

Another question, is there now a direct method for reading members guild tag?
the server tag
like here "PYC"

round heart
#

Has this changed on 2.7?

quasi dune
obsidian glacier
#

Oh I wasn't sure if that's the correct thing

#

will try that, thank you

quasi dune
obsidian glacier
quasi dune
#

What about primary_guild.tag

obsidian glacier
#

that works perfectly, thank you so much!

quasi dune
#

\0/

obsidian glacier
#

I can now update my Tag checker, finally

#

Discord always timeouted me via the API cry

sage tendon
frail basin
errant trout
# frail basin Never understood why manually creating a ui component expects different args tha...

when you create it separately, you're already able to reference the item ```py
button = Button(...)
async def callback(interaction):
button.label = ...

or...

class MyButton(Button):
async def callback(self, interaction):
self.label = ... # self is the buttonbut with the decorator, the object does not exist anywhere else - the function *is* your button, and there's no way to reference it without inserting it as the function arg py
class MyView(View):
@button(...)
async def some_callback(self, button, interaction):
button.label = ...```

frail basin
errant trout
#

it IS documented, you just have to read

#

(understandably not everyone reads docs thoroughly, but it is there regardless)

unkempt cipher
quasi dune
timid shuttleBOT
#

Meow

quasi dune
#

LMAO

unkempt cipher
#

sure

timid shuttleBOT
#

This thread is archived now. Please use #1411737823635312693