#πŸ”’ Nothing is printing (Not the only thing), database isn't being reached at all, but code is executi

4 messages Β· Page 1 of 1 (latest)

untold yoke
#

I'm working on a mental health bot for people to be able to vent and explain their frustrations without anyone in the server knowing who they are.

Vent Command:

    @app_commands.command(name="send", description="Send an anonymous message")
    async def vent(self, interaction: discord.Interaction, message: str):
        vent_channel = self.bot.get_channel(self.vent_channel_id)

        if not vent_channel:
            await interaction.response.send_message("The venting channel is not set up correctly.", ephemeral=True)
            return

        await interaction.response.send_message("Your anonymous message has been sent.", ephemeral=True)

        # Create a new thread for the anonymous message
        timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        thread = await vent_channel.create_thread(
            name=f"Anonymous Vent - {timestamp}",
            type=discord.ChannelType.public_thread
        )

        # Post the user's anonymous message in the thread
        embed = discord.Embed(description=message, color=discord.Color.purple())
        embed.set_footer(text="Anonymous Message - /venting send")
        embed.set_author(name="A user has started an anonymous thread")
        print(interaction.user.id, thread.id, message, timestamp)
        try:
            print("About to call log_thread...")
            await log_thread(interaction.user.id, thread.id, message, timestamp)
            print("log_thread was called")
        except Exception as e:
            print(f"Error calling log_thread: {traceback.format_exc()}")
        sent_message = await thread.send(embed=embed)```

Now what this is, is pretty understable. It takes a users message after doing a couple of checks, and then creates a thread, sets up the embed, then logs the thread into the database, then sends the message to the thread. 

Now the main issue is that the thread isn't able to be logged into the database for some reason. The prints I added for debugging don't print at ALL, even the ones before the function is called. But the thread opens, and the message is sent to the thread (which is AFTER the thread should be logged) so I'm just extremely confused.

db.py LogThread function:

```py
async def log_thread(user_id, thread_id, original_message, timestamp):
    print(f"Logging thread: {thread_id} by user {user_id}")
    async with aiosqlite.connect("venting_bot.db") as db:
        try:
            await db.execute("""
                INSERT OR IGNORE INTO threads (user_id, thread_id, original_message, timestamp)
                VALUES (?, ?, ?, ?)
            """, (user_id, thread_id, original_message, timestamp))
            await db.commit()
            print(f"Thread logged: {thread_id} by user {user_id}")
        except Exception as e:
            print(f"Error logging thread: {traceback.format_exc()}")```
uncut spindleBOT
#

@untold yoke

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

uncut spindleBOT
#

@untold yoke

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.