How can I make this bot send multiple messages if the message is > 2000 characters, so…
- User
How can I make this bot send multiple messages if the message is > 2000 characters, so discord won't give any issues about it? @bot.event async def on_message(message): if message.author == bot.user: return await bot.process_commands(message) if isinstance(message.channel, discord.channel.DMChannel) or (bot.user and bot.user.mentioned_in(message)): if message.reference: pastMessage = await message.channel.fetch_message(message.reference.message_id) else: pastMessage = None past_messages = await fetch_past_messages(message.channel) message_content = replace_mentions_with_nothing(message.content, message) message_content, temperature, rep_penalty = parse_flags(message_content) # Add this line
codeprompt = generate_prompt(message_content, pastMessage, past_messages) async with message.channel.typing(): response = await call_rest_api(prompt, temperature, rep_penalty) # Modify this line retry_count = 0 max_retries = 3 while "<nooutput>" in response and retry_count < max_retries: response = await call_rest_api(prompt, temperature, rep_penalty) # Modify this line retry_count += 1 print("<nooutput> in response, trying again.") bot_message = await message.reply(response, mention_author=False) await add_reactions(bot_message) # Add reactions to the bot's message - Assistant
To implement a bot that sends multiple messages when the output exceeds Discord's maximum character limit (2000 characters), you need to add a check on the character count of the response and divide it into chunks accordingly.
Here is a modification to your bot's code that implements this functionality: