This repository has been archived by the owner on Aug 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGreenBOT.py
81 lines (66 loc) · 2.91 KB
/
GreenBOT.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
76
77
78
79
80
81
# Imports
import discord
from discord.ext import commands
import random
import sys, traceback
import pickle
# Sets prfix for the bot
def get_prefix(bot, message):
"""A callable Prefix for our bot. This could be edited to allow per server prefixes."""
# Check to see if we are outside of a guild. e.g DM's etc.
if not message.guild:
# Only allow this prefix to be used in DMs
return ['&&']
#Get the prefix data
pList = {}
pList = pickle.load(open('data/prefix.data', 'rb'))
#Finds the prefix in the data.
try:
prefix = pList[f'{message.guild.id}']
#If there's no prefix for the server, set it to default.
except KeyError:
prefix = ['&&']
# 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(*prefix)(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.base.help',
'cogs.base.custom',
'cogs.base.error_handler',
'cogs.base.listener',
'cogs.base.owner',
'cogs.other.credits',
'cogs.other.misc',
'cogs.other.mindustry',
'cogs.ss.botmod',
'cogs.ss.CP',
'cogs.ss.gear5',
'cogs.ss.scrim',
'cogs.ss.BL']
# Defines the bot
bot = commands.Bot(command_prefix=get_prefix, description="A Greenfoot5 bot.", self_bot=False)
# Removes the help command so we can add our own custom one.
bot.remove_command('help')
# Here we load our extensions(cogs) listed above in [initial_extensions].
if __name__ == '__main__':
for extension in initial_extensions:
try:
# Appempts to load the extension
bot.load_extension(extension)
print(f"Successfully loaded extension - {extension}")
except Exception as e:
# Outputs an error if there was an issue.
print(f"Failed to load extension {extension}.", file=sys.stderr)
traceback.print_exc()
@bot.event
async def on_ready():
# Called when the bot loads.
# Displays the current bot and it's version.
print(f'\n\nLogged in as: {bot.user.name} - {bot.user.id}\nVersion: 2.1.1\n')
# Changes our bots Playing Status. type=1(streaming) for a standard game you could remove type and url.
await bot.change_presence(activity=discord.Activity(name="GreenBOT 2.1.1",type=0))
print(f'Successfully logged in and booted!\n')
print("Connecting to discordapp...")
# Loads our token and starts the bot.
tooken = pickle.load(open('tooken.data','rb'))
bot.run(tooken, bot=True, reconnect=True)