-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
executable file
·75 lines (56 loc) · 1.84 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import pathlib
import discord
from discord.ext import commands
from dotenv import load_dotenv
from src.copypasta import copypasta_dict
# Load in environment variables
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
# Create bot client
intents = discord.Intents.all()
activity = discord.Activity(type=discord.ActivityType.listening, name="i-")
bot = commands.Bot(command_prefix='i-', activity=activity, status=discord.Status.online, intents=intents)
# Load extensions/cogs
path = pathlib.Path(__file__).parent
for cog in os.listdir(path / "cogs"):
if cog.endswith('.py'):
try:
bot.load_extension('cogs.' + cog.removesuffix('.py'))
except Exception as e:
print("There has been an error loading a cog")
raise e
# Tells when bot is ready
@bot.event
async def on_ready():
print("Ready!")
# Calls every message
@bot.event
async def on_message(message):
# Don't call if message written by a bot
if message.author.bot:
return
# Copypasta handler (and gay anime gifs ofc)
contents = message.content.split()
for word in contents:
if word.lower() in copypasta_dict or word in copypasta_dict:
try:
msg_parts = copypasta_dict[word.lower()].split('\n')
except KeyError:
msg_parts = copypasta_dict[word].split('\n')
for part in msg_parts:
await message.channel.send(part)
break
# Process other commands if applicable
await bot.process_commands(message)
# Command error handler
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
await ctx.send("That is not a command!")
return
if ctx.command.has_error_handler() or ctx.cog.has_error_handler():
return
raise error
# Run bot
bot.run(TOKEN)