Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import io
- import aiohttp
- import discord
- from PIL import Image, ImageDraw, ImageFont
- import password_generator
- class MyClient(discord.Client):
- async def on_ready(self):
- print('Logged in as')
- print(self.user.name)
- print(self.user.id)
- print('------')
- async def on_message(self, message):
- # we do not want the bot to reply to itself
- if message.author.id == self.user.id:
- return
- if message.content.startswith('Hello'):
- await message.channel.send('Hello! \nUse prefix "$" before commands')
- if message.content.startswith('$picture'):
- await message.channel.send('Choose option: url or file')
- if message.content.startswith('$url'):
- await message.channel.send('Send your text and url')
- m = await self.wait_for('message')
- cont = m.content.split()
- async with aiohttp.ClientSession() as session:
- async with session.get(cont[-1]) as resp:
- if resp.status != 200:
- return await message.channel.send('Could not download file...')
- image_file = io.BytesIO(await resp.read())
- im, txt = Image.open(image_file), ' '.join(cont[:len(cont) - 1])
- font = ImageFont.truetype(
- r'S:\drive.google.com\file\d\1Ho7TxrfN8drGMTLf39Ozupys0leACmpk\view?usp=sharing', size=75)
- draw_text = ImageDraw.Draw(im)
- width, height = draw_text.textsize(txt, font=font)
- position: tuple = ((im.width - width) / 2, im.height - 100)
- draw_text.text(position, txt, font=font, fill='#FF0000')
- image_content = io.BytesIO()
- im.seek(0)
- im.save(image_content, format='JPEG')
- image_content.seek(0)
- await message.channel.send(file=discord.File(image_content, 'cool_image.png'))
- if message.content.startswith('$file'):
- await message.channel.send('Send your text and path to your image file')
- m = await self.wait_for('message')
- cont = m.content.split()
- im, txt, pallet = Image.open(cont[-1]), ' '.join(cont[:len(cont) - 1]), {'red': '#FF0000',
- 'black': '#000000',
- 'white': '#FFFFFF',
- 'blue': '#0000FF',
- 'grey': '#C0C0C0'}
- font = ImageFont.truetype(r'C:\Users\MAX-Ryzen\Desktop\Roboto\Roboto-Black.ttf', size=75)
- draw_text = ImageDraw.Draw(im)
- width, height = draw_text.textsize(txt, font=font)
- position: tuple = ((im.width - width) / 2, im.height - 100)
- draw_text.text(position, txt, font=font, fill='#FF0000')
- image_content = io.BytesIO()
- im.seek(0)
- im.save(image_content, format='JPEG')
- image_content.seek(0)
- await message.channel.send(file=discord.File(image_content, 'cool_image.png'))
- client = MyClient()
- client.run('NzgwNzQwMzE1NjMxODQ1Mzg2.X7zfFA.9xQQzz-DrgeLfkoSgBnw46zbi9g')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement