#Basic Pycord Help
1 messages · Page 80 of 1
What do you mean ?
Probably would be easier to use some dataclass
this technically works and won't mess with cache, but i'm not sure why you're doing this at all
I want to test my reply generator's placeholders, without having to actually run the commands/buttons/etc necessary to trigger it normally.
no idea if copy deep copies but you probably should if it doesn't
It just calls __new__ and manually sets attributes
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
I dont know what the end user will need in terms of properties and all
so I want to provide everything
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
are you making a mocking framework or
sounds like a ticket system or something to me but eh vague guess
I am letting the user pass raw json as for bot replies and then rendering it using jinja2
bruh
Dw this is a private commission not a public thing
lol
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, justget_or_fetch_useron client
i guess I could just fetch a random thread
if you really want yeah that works
I assume interaction.user would be User in dms and Member in guilds?
yea
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)
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?
Did you edit interaction.view directly
I thought I needed to create a new View instance and put the modified list of items there - await interaction.response.edit_message(view=View(*interaction.view.children)). But still nothing changes(
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)
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
I am sure that section[0] has completely different elements with different text content. I did everything based on the example of new components on GitHub.
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?
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...)
I used a loop to add elements with interaction.view to a new view instance. When I found the right ID, I changed it to the modified section. It worked! Thank you very much!
When I enter the command, the emoji appears, but when someone else enters it, it doesn't appear.

That?
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
I'm going to try with an emoji that is in the bot itself and not on a server.
yea thatll work for sure
I didn't get it 
mhm
I'll have to move all the emojis 
Thank you very much, sorry for the inconvenience

what
thats for timestamps lol
For consistent emoji behavior in user apps you have to use app emojis.
still feels like a bug
That page, no?
Is there a way to call this section to get the emojis dynamically? or only copy id an format ?

https://discord.com/api/v10/applications/{app_id}/emojis with the bot token as auth
if you use the master branch, it's in bot.emojis
actually apparently it's https://docs.pycord.dev/en/master/api/clients.html#discord.Bot.app_emojis
Bots: Attributes activity, allowed_mentions, app_emojis, application_flags, application_id, auto_sync_commands, cached_messages, cogs, debug_guilds, default_command_contexts, default_command_integr...
stable version is 2.6.1?
yes
that true
Is there a date for 2.7?
no

been using since months 
no issues
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
nope
dismissing doesn't even count as a delete, it just hides it on that client
if youre trying to handle buttons, just disable the view on timeout
I do, but I'm finding my users are incredibly dumb 
if they cant press the button nothing can go wrong 
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
but you are editing the message to make the button be disabled right
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
channel_types
list of discord.ChannelType enum
oh ok
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])```
oh that worked, thank you
you don't need required=True btw
Toothy, you would not have been happy with krittick, they preferred everything to be explicit
just wanna let them know
what they do with it is their problem
Yes, I disable all children then I add an embed with "this interaction has timed out"
So, I still give the dumb ones a warning
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?
no there isn't
oh ok
I understand what eventually happened, but I do miss krittick
Reminder for @echo wraith
wtf
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
.tag audioop
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.
Is Master already installing audioop ?
it has its own implementation
that does not rely on it anymore
Oh nice
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?
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
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
can you show it
Do you want the log snippet or a video of the whole flow from the discord client side as well?
just the traceback
Sure give me a few minutes
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
can you please try on master ?
.tag master
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/
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.
What is opus frame??
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.
Opus is the audio library pycord depends on according to the docs
@errant trout Why has this not been merged or at least PRed?
https://github.com/NeloBlivion/pycord/tree/voice_dep
github moment
I never used voice channel stuff at my bot so uhm
are you sure this is the most recent master? It seems to have fixed it for the other person with this problem
This is my requirements.txt: git+https://github.com/Pycord-Development/pycord.git@master Is that correct?
.tag master
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?
I think you only need this
git+https://github.com/Pycord-Development/pycord
Just install that again, incase you were on an older commit
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()
I dont have time to look at it now sorry
No problem. Whenever you get the chance let me know if there’s any other info you need
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?
if you have control over which servers the bot is in, go to guild settings > integrations to adjust the permissions
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
if that works then sure, but editing it in guild settings will also hide the command from people who don't have the role
If they are all in the same guild, register it as a guild command
Why are we fetching the member
interaction.author has almost everything
Presences data is the only thing missing afaik
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.
btw you can use discord.utils.get_or_fetch for this I think
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
just import datetime
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 ^.^)
generally, custom_id is not required at all in pycord v2
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
(because custom_id is a string and id is an int)
This is what tripped me up
basically, if you want to conveniently get an item at some point later on, setting id is useful
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
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? 
all interactible items need custom_ids
ah yea, just button and select
ie buttons & selects
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.
OH I literally just saw the example and how get_item(id) works now. (you know, like 45 minutes after the conversation is over lol)
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)
does it take 3 seconds to show that? (roughly)
stop the bot and run the command again
restart your client
Fixed it, it was because the "prod" version was still running too
yea i guessed so lol
how can you edit ephemeral msgs?
Same as any normal message.
discord.errors.NotFound: 404 Not Found (error code: 10008): Unknown Message
try Interaction.delete_original_response
trying to do view -> modal btw if that matters
nvm ive got it
ty tho
What are the minimum specs an average discord bot needs to run on a vps?
Idk you can live on under 1gb ram
How many servers/members does your bot have
Like 3 servers with 500members each
I guess the most intense task is adding 500members to a thread
isn't it easier to either ping them or make a channel
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?
more is never bad
Kinda not what I asked tbh
My bot uses around 1.1gb
Its handles 1 server of 500 members plus a web server
1gb is more than enough for your member counts
Thx :))))
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)
You are required to have an accessory in sections, I assume you have a section in your container
am I required to have a section?
no
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```
You can just add those 3 text displays to the container
like this? container = Container(title, queue_str, footer, color=self.bot.color)
(Also you can put them all in one text display to save componenets)
should work i think.
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
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
Its be cool to create a visual thing
discord.builders abstracts it
I think discohook hasa visual builder
Section is just text with thumbnail/button on the right
(But may be expanded in future)
so if I don't want button/thumbnail on the right I don't need section
Oh right I wanted to add an arg to decorators to let them be added at the end
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'
your callback has a wrong set of args
callback has self, button, and interaction
gotcha
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
Another question, is there now a direct method for reading members guild tag?
the server tag
like here "PYC"
Has this changed on 2.7?
Looks like you can access user.primary_guild now?
If it's not lemme know so I don't operate under that assumption LOL
Yeah so user.primary_guild responds with:
<PrimaryGuild identity_guild_id=1370009123189424209 identity_enabled=True tag=SOKA>
What about primary_guild.tag
that works perfectly, thank you so much!
\0/
I can now update my Tag checker, finally
Discord always timeouted me via the API 
this will still work, if you're curious
Never understood why manually creating a ui component expects different args than with the decorator
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 = ...```
I know, but afaik this isnt documented anywhere and is very confusing for new devs (like it was for me)
it IS documented, you just have to read
https://docs.pycord.dev/en/master/api/ui_kit.html#discord.ui.button
A decorator that attaches a button to a component.
The function being decorated should have three parameters,
selfrepresenting thediscord.ui.View, thediscord.ui.Buttonbeing pressed and thediscord.Interactionyou receive.
https://docs.pycord.dev/en/master/api/ui_kit.html#discord.ui.Button.callback
Parameters:
interaction (Interaction) – The interaction that triggered this UI item.
(understandably not everyone reads docs thoroughly, but it is there regardless)
oh nice to see u alive :D
Hiii I live!
Meow
I was gonna start a casual chat, but I dun wanna clog up the help channel, can I DM you? ^.^
LMAO
sure
This thread is archived now. Please use #1411737823635312693