forked from msaroufim/Discord-PDFPreview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
42 lines (29 loc) · 1021 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Work with Python 3.6
import discord
import requests
import pdf2image
import io
TOKEN = 'PUT_TOKEN_HERE'
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!hello'):
msg = 'Hello {0.author.mention}'.format(message)
await client.send_message(message.channel, msg)
if message.content.endswith('.pdf'):
pdf = requests.get(message.content)
#slideshow sounds awesome actually
## should only get the first image, getting entire pdf is kinda dumb
screenshot = pdf2image.convert_from_bytes(pdf.content)[0]
screenshot.save("screenshot.png", filename="screenshot.png")
await client.send_file(message.channel, "screenshot.png")
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run(TOKEN)