#!/usr/bin/env python3 # encoding: utf-8 import discord from discord.ext import commands import io from patch import global_message_send_hook bot = commands.Bot(command_prefix=commands.when_mentioned) @global_message_send_hook async def attach_if_too_long(original_send, message=None, *args, **kwargs): if message is None: return True, message = str(message) if len(message) > 2000: file = discord.File(fp=io.StringIO(message), filename='message.txt') message = await original_send('Way too long. Message attached.', *args, **kwargs, file=file) return False, message return True, @bot.command() async def send_big_message(context): print((await context.send('aA'*1001)).id) @bot.event async def on_ready(): print('Ready.') if __name__ == '__main__': import os bot.run(os.environ['discord_bot_token'])