Темы форума Discord.py, недопустимое тело формыPython

Программы на Python
Anonymous
Темы форума Discord.py, недопустимое тело формы

Сообщение Anonymous »

Я пытаюсь связать свою электронную таблицу Google с ветками форума Discord, и я получаю эти ошибки, в которых говорится, что это недопустимое тело формы из-за превышения ограничения на количество символов в 2000 или 4000, и если я это изменю, это будет сказать, что он не может отправить пустое сообщение. Я заставил его отправить первое сообщение, но у меня возникла проблема с тем, когда оно дойдет до второго сообщения, если это необходимо.

Код: Выделить всё

 async def post_to_discord(self, title, content):
"""Post the content to the forum channel on Discord."""
forum_channel = self.bot.get_channel(self.forum_channel_id)

if not forum_channel:
print(f"Error: Channel {self.forum_channel_id} not found.")
return

# Ensure that the title and content are not empty
if not title or not content.strip():
print(f"Error: Title or content for entry '{title}' is empty.")
return

try:
# Prepare the formatted content with the title at the top
thread_content = f"**Title:** {title}\n\n**Content:**\n{content.strip()}"

# Create a thread with the initial message in the forum channel
thread = await forum_channel.create_thread(
name=f"New Entry - {title}",
content=thread_content,  # The first post in the forum thread
auto_archive_duration=1440  # 24 hours
)

# Handle splitting the content if it exceeds 2000 characters
max_message_length = 1990
split_messages = [thread_content[i:i + max_message_length]
for i in range(0, len(thread_content), max_message_length)]

# Send additional messages in the same thread if necessary
for message in split_messages[1:]:
if message.strip():  # Ensure the message is not empty
print("Sending additional message to the thread...")
await thread.send(message.strip())
print("Additional message sent successfully.")

print(f"New entry '{title}' posted successfully.")

except Exception as e:
print(f"Error occurred while posting to Discord: {e}")
Что он должен сделать, так это отправить начальное сообщение длиной 2000 символов и, если оно превышает это значение, разделить сообщение на несколько в ветке. В этом порядке сообщения, сообщения, сообщения или даже сообщения, сообщения или просто сообщения в зависимости от количества символов. На фото вы можете увидеть лог того, что пытается сделать бот.

Подробнее здесь: https://stackoverflow.com/questions/790 ... -form-body

Вернуться в «Python»