-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (36 loc) · 1.13 KB
/
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
41
42
43
import discord
import os
from dotenv import load_dotenv
from qr_code_generator import convert_to_qr
import io
# Load the .env file
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
# Bot setup
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
# Bot startup
@client.event
async def on_ready():
print(f'{client.user} is ready to go!')
# Bot message handling and QR code generation
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('!'):
try:
print(f'{message.author} in {message.channel} said: {message.content}')
data = message.content[1:]
img = convert_to_qr(data)
image_binary = io.BytesIO()
img.save(image_binary, 'PNG')
image_binary.seek(0)
await message.channel.send('Here is your QR code!')
await message.channel.send(file=discord.File(fp=image_binary, filename='qr_code.png'))
image_binary.close()
return
except Exception as e:
print(e)
client.run(TOKEN)