-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
51 lines (39 loc) · 1.16 KB
/
bot.py
File metadata and controls
51 lines (39 loc) · 1.16 KB
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
44
45
46
47
48
49
50
51
import os
import re
from dotenv import load_dotenv
import random
import discord
from discord.ext import commands
from keep_alive import keep_alive
intents = discord.Intents.default()
intents.message_content = True
intents.emojis = True
intents.guilds = True
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.event
async def on_ready():
print(f'✅ Logged in as {bot.user}')
@bot.event
async def on_message(message):
if message.author.bot:
return
emojis = message.guild.emojis
if message.content.isdigit():
if emojis:
emoji = random.choice(emojis)
await message.add_reaction(emoji)
content = message.content.strip()
if re.match(r'^[\d\s+\-*/().]+$', content):
try:
expr = content.replace(' ', '')
result = eval(expr, {"__builtins__": {}}, {})
if result is not None and result == int(result):
if emojis:
emoji = random.choice(emojis)
await message.add_reaction(emoji)
except:
pass
await bot.process_commands(message)
load_dotenv()
keep_alive()
bot.run(os.getenv('DISCORD_TOKEN'))