This repository has been archived by the owner on Oct 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathBot.py
74 lines (57 loc) · 2.73 KB
/
Bot.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
import discord
from discord.ext import commands
from os import environ
import asyncio
import sys, traceback
"""This is a multi file example showcasing many features of the command extension and the use of cogs.
These are examples only and are not intended to be used as a fully functioning bot. Rather they should give you a basic
understanding and platform for creating your own bot.
These examples make use of Python 3.6.2 and the rewrite version on the lib.
For examples on cogs for the async version:
https://gist.github.com/leovoel/46cd89ed6a8f41fd09c5
Rewrite Documentation:
http://discordpy.readthedocs.io/en/rewrite/api.html
Rewrite Commands Documentation:
http://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html
Familiarising yourself with the documentation will greatly help you in creating your bot and using cogs.
"""
def get_prefix(bot, message):
"""A callable Prefix for our bot. This could be edited to allow per server prefixes."""
# Notice how you can use spaces in prefixes. Try to keep them simple though.
prefixes = ['o.', 'o?','!','.','o!','?']
# Check to see if we are outside of a guild. e.g DM's etc.
#if not message.guild:
# Only allow ? to be used in DMs
# return '.'
# If we are in a guild, we allow for the user to mention us or use any of the prefixes in our list.
return commands.when_mentioned_or(*prefixes)(bot, message)
# Below cogs represents our folder our cogs are in. Following is the file name. So 'meme.py' in cogs, would be cogs.meme
# Think of it like a dot path import
#initial_extensions = ['cogs.The_Alchemist_Code',
# 'cogs.TAC_Discord'
# ]
TAC_BOT = commands.Bot(command_prefix='o.', description='The Alchemist Code bot, written by W0lf in discord.py')
TAC_DISCORD = commands.Bot(command_prefix='!', description='The Alchemist Code discord bot, written by W0lf in discord.py')
# Here we load our extensions(cogs) listed above in [initial_extensions].
if __name__ == '__main__':
TAC_BOT.load_extension('cogs.The_Alchemist_Code')
TAC_BOT.load_extension('cogs.Spy')
TAC_DISCORD.load_extension('cogs.TAC_Discord')
TAC_DISCORD.load_extension('cogs.TAC_FID')
TAC_DISCORD.load_extension('cogs.Spy')
# for extension in initial_extensions:
# try:
# bot.load_extension(extension)
# except Exception as e:
# print(f'Failed to load extension {extension}.', file=sys.stderr)
# traceback.print_exc()
#Create the loop
loop = asyncio.get_event_loop()
#Create each bot task
loop.create_task(TAC_DISCORD.start(environ.get('DISCORD_BOT_TOKEN_ROLES'), bot=True, reconnect=True, case_sensitive=False))
loop.create_task(TAC_BOT.start(environ.get('DISCORD_BOT_TOKEN'), bot=True, reconnect=True, case_sensitive=False))
#Run loop and catch exception to stop it
try:
loop.run_forever()
finally:
loop.stop()