-
Notifications
You must be signed in to change notification settings - Fork 0
/
elfbot.py
65 lines (47 loc) · 2.12 KB
/
elfbot.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
from discord.ext.commands import Bot, Context, MissingRequiredArgument, MissingPermissions, CommandNotFound
from discord import Activity, ActivityType, Message
from extensions.music_handler import process_msg_for_music
from extensions.prefix_handler import get_prefix, get_prefix_for_guild
from utils.utils import *
elfbot = Bot(command_prefix=get_prefix) # callable prefix - invoked on every message
@elfbot.event
async def on_ready():
await elfbot.change_presence(
activity=Activity(type=ActivityType.watching, name='for music spam 👀')
)
log_event(f'{elfbot.user} is Online')
@elfbot.event
async def on_command_error(ctx: Context, error):
if isinstance(error, CommandNotFound):
return
if isinstance(error, MissingRequiredArgument):
await ctx.send(f'Please use the command with the required argument: <{error.param}>')
elif isinstance(error, MissingPermissions):
log_event(f"<server='{ctx.guild}'> {ctx.author} tried using a restricted command ({ctx.command})", logging.WARN)
await ctx.send(f"{ctx.author.mention} you don't have enough permissions to use {ctx.command}")
else:
log_event(f"<server='{ctx.guild}'> An Error Occurred! - [Error: {error} | Command: {ctx.command} |"
f" Author: {ctx.author}]", logging.CRITICAL)
@elfbot.event
async def on_message(message: Message):
if message is None:
return
if message.author == elfbot.user:
return
if not message.guild: # DM case
return
if elfbot.user.mentioned_in(message):
pf = get_prefix_for_guild(message.guild.id)
await message.channel.send(
f'{message.author.mention}\nMy prefix in this server is {pf}\nUse "{pf}help" for more info'
)
return
if await process_msg_for_music(message, elfbot):
return
await elfbot.process_commands(message)
if __name__ == '__main__':
# load all extensions
for filename in os.listdir('extensions'):
if filename.endswith('.py') and 'template' not in filename:
elfbot.load_extension(f'extensions.{filename[:-3]}')
elfbot.run(get_token())