Reason: Duplicated text
#Python Discord Bot
1 messages · Page 1 of 1 (latest)
huh
How can I make my discord bot send a message on a thread? I have many channels, all of them have thread, and it's name is consistent across all channels, and I want to make it send a message whenever I issue one specific command.
print(f"Thread not found. Creating new thread: {THREAD_NAME}") #variable declated earlier into the code
thread = await interaction.channel.create_thread(
name=THREAD_NAME,
type=discord.ChannelType.public_thread
)
else:
if thread.archived:
print(f"Unarchiving thread: {thread.name}")
await thread.edit(archived=False)
additional_message = f"Thread Updated"
await thread.send(additional_message)
except Exception as e:
print(f":warning: Error handling thread: {e}")
await interaction.followup.send(
":warning: Failed to update thread",
ephemeral=True
)
return
why can't you just grab the thread id and send it
because there are many many channels
thread id are unique?
all of them got stored id's on a database in sqlite3
yeah, just like channels
so whats holding u back from sending messages to a "thread"
as i said thread ids r unique and u can differ which is which therefore i dont get why u cant just send the wanted message to that thread
well, I don't have them stored alongside with the channel ID's
so u have the channel id stored but not the thread ids?
because it's many threads with a consistent name along many channels, so I'm trying to send a message by trying to catch the thread name, but always running into the exception
then get the specific channel and then use .threads
if theres no other way, i think you can leave a message and try to get a certain message/apply tags from those consistently name threads to filter them out?
yeah, got it now, many thanks, had to do this way ->
channel = interaction.channel
thread = discord.utils.get(channel.threads, name=THREAD_NAME)
if thread is None:
print(f"Thread '{THREAD_NAME}' not found in channel {channel.name}. Creating a new thread...")
thread = await channel.create_thread(
name=THREAD_NAME,
type=discord.ChannelType.public_thread
)
print(f"Created new thread: {thread.name}")
else:
print(f"Found existing thread: {thread.name}")
if thread.archived:
print(f"Unarchiving thread: {thread.name}")
await thread.edit(archived=False)
additional_message = f"Thread Updated by {interaction.user.display_name}"
await thread.send(additional_message)
print(f"Thread updated successfully!")
except Exception as e:
print(f":warning: Error handling thread: {e}")
await interaction.followup.send(
"Failed to update thread!",
ephemeral=True
)
🙏