#Thread archived
1 messages · Page 1 of 1 (latest)
That's now how python works.
You need an instance if the Guild object, usually from inter.guild
Then you have to actually CALL the method ()
th = inter.guild.get_thread(THREAD_ID)
If you then want to archive it you have to edit the thread, looking at th.archived will just provide a boolean for whether the thread is archived or not
True if the thread is archived, else False
So, what you probably are wanting to something like this:
th = inter.guild.get_thread(THREAD_ID)
if not th.archived: # th.archived would be False, so let's archive it.
await th.edit(archived=True)
-d disnake.Thread
class disnake.Thread```
Represents a Discord thread.
x == y Checks if two threads are equal.
x != y Checks if two threads are not equal.
hash(x) Returns the thread’s hash.
str(x) Returns the thread’s name.
New in version 2.0.
-d disnake.Thread.edit
await edit(*, name=..., archived=..., locked=..., invitable=..., slowmode_delay=..., auto_archive_duration=..., pinned=..., flags=..., applied_tags=..., reason=None)```
This function is a [*coroutine*](https://docs.python.org/3/library/asyncio-task.html#coroutine).
Edits the thread.
Editing the thread requires [`Permissions.manage_threads`](https://docs.disnake.dev/en/latest/api/permissions.html#disnake.Permissions.manage_threads "disnake.Permissions.manage_threads"). The thread creator can also edit `name`, `archived`, `auto_archive_duration` and `applied_tags`. Note that if the thread is locked then only those with [`Permissions.manage_threads`](https://docs.disnake.dev/en/latest/api/permissions.html#disnake.Permissions.manage_threads "disnake.Permissions.manage_threads") can unarchive a thread.
The thread must be unarchived to be edited.
thanks for the help
You're welcome, but do you understand why this is the solution?
As I understand it, you can’t send it to the archive like that, you can only change the status
Becauase th.archived is an attribute. It's essentially just information about the object (in this case the Thread object)
To actually change that, you have to perform an API request that tells discord to archive the thread. At that point, the attribute value is updated.
It's very important that you understand classes, instances, attributes, and methods and the difference between them and how they work.
And why await inter.thread.archived(th) throws the error you received.
Generally he complained about thread here
Right, because you tried to access a thread attribute from inter which is an ApplicationCommandInteraction object which does not contain a thread attribute.
-d disnake.ApplicationCommandInteraction
class disnake.ApplicationCommandInteraction```
Represents an interaction with an application command.
Current examples are slash commands, user commands and message commands.
New in version 2.1.
Learning how to read and understand the docs is a quite important skill to learn when working with libs
But to do that you'll need to spend some time learning Python
I understand, I'm learning slowly. With examples like this, everything becomes clearer)
That's good news!
Enjoy. It's a fun and powerful language.
If you're happy with the solution, please use /solved
Can you tell me right away how I can get the thread ID?
Depends on what you're trying to do
If you're trying to use a command to archive/close a thread, you can have the command user provide it.
Basically I'm trying to do as here
And that's pretty easy with slash commands. Just need to add a parameter to yoru command and annotate that it should be a Thread object. Then you don't even need to "get_thread" at all, it will already be provided within the command function
@command.slash_command(name='archive_thread')
async def archive_thread(self, inter: disnake.GuildCommandInteraction, thread: disnake.Thread):
if not thread.archived:
await thread.edit(archived=True)
return await inter.response.send_message(f'{thread.name} has been archived by {inter.author.mention}')
return await inter.response.send_message(f'{thread.name} was unable to be archived. REASON: Thread already archived', ephemeral=True)
or something like that
Everything turned out to be easier than I thought)
Thanks again
While slash commands do have their issues and shortcomings, they do make a lot of things much easier to code.
I was lucky as long as I didn't encounter any flaws
Comprehending error messages is a huge part of development. And disnake's docs and error messages tend to be quite good compared to many libs out there.
Yes, it's really quite clear here
clear as mud? 😄
😁