Moved cog loading into __init__.py

pull/8/head
sgoudham 4 years ago
parent 71e5088b3b
commit 099af46d49

@ -11,6 +11,7 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
import datetime import datetime
import os
import random import random
import aiohttp import aiohttp
@ -529,18 +530,15 @@ class Bot(commands.Bot):
# --------------------------------------------!End Events Section!---------------------------------------------- # --------------------------------------------!End Events Section!----------------------------------------------
def run_bot(self): def Run(self):
"""Load the cogs and then run the bot"""
for file in os.listdir(f'.{os.sep}cogs'):
if file.endswith('.py'):
self.load_extension(f"cogs.{file[:-3]}")
# Run the bot, allowing it to come online # Run the bot, allowing it to come online
try: try:
self.run(API_TOKEN) self.run(API_TOKEN)
except discord.errors.LoginFailure as e: except discord.errors.LoginFailure as e:
print(e, "Login unsuccessful.") print(e, "Login unsuccessful.")
# Returns a list of all the cogs
def extensions(self):
ext = ['cogs.interactive', 'cogs.anime', 'cogs.relationship',
'cogs.help', 'cogs.info', 'cogs.guild', 'cogs.fun', "cogs.error",
'cogs.enso', 'cogs.owner', 'cogs.moderation']
return ext

@ -15,15 +15,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
# Initiating Bot Object As Client from bot import Bot
from bot.__init__ import Bot
client = Bot()
if __name__ == '__main__':
for ext in client.extensions():
client.load_extension(ext)
# Initiating Bot Object As Client
# Run the bot # Run the bot
client.run_bot() client = Bot().Run()

Loading…
Cancel
Save