Update bot.py

This commit is contained in:
ElBe 2022-10-17 14:09:16 +02:00 committed by GitHub
parent 945dee2346
commit 38f79418dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,7 +17,7 @@ import psutil
#Bot modules #Bot modules
import functions import functions
import commands
#Start #Start
print('Discord.py Bot') print('Discord.py Bot')
print('----------------------------') print('----------------------------')
@ -42,6 +42,7 @@ MISSING = utils.MISSING
starttime = time.time() starttime = time.time()
#JSON data #JSON data
try:
token = functions.json_module.get_config('Config')['Token'] token = functions.json_module.get_config('Config')['Token']
version = functions.json_module.get_config('Config')['Version'] version = functions.json_module.get_config('Config')['Version']
credits = functions.json_module.get_config('Config')['Credits'] credits = functions.json_module.get_config('Config')['Credits']
@ -49,11 +50,20 @@ footer = functions.json_module.get_config('Config')['Footer']
welcomeChannel = functions.json_module.get_config('Channels')['Welcome'] welcomeChannel = functions.json_module.get_config('Channels')['Welcome']
goodbyeChannel = functions.json_module.get_config('Channels')['Goodbye'] goodbyeChannel = functions.json_module.get_config('Channels')['Goodbye']
commands = functions.json_module.get_config('Commands') commands = functions.json_module.get_config('Commands')
except Exception as e:
print(functions.console.error('Error while trying to get data from the config file.\n' + str(e)))
#Setup #Setup
logging.basicConfig(filename='log.txt', level=logging.INFO) logging.basicConfig(filename='log.txt', level=logging.INFO)
intents = discord.Intents.all() intents = discord.Intents.all()
#Create commands
try:
if functions.json_module.get_config('Created', 'commands.json') == 0:
commands.run()
except Exception as e:
print(functions.console.error('Error while trying to create the commands.\n' + str(e)))
#Main #Main
class Bot(discord.Client): class Bot(discord.Client):
'''Bot.''' '''Bot.'''
@ -65,6 +75,7 @@ class Bot(discord.Client):
async def on_ready(self): async def on_ready(self):
logging.info(str(datetime.datetime.now()) + ' Bot logged in as ' + client.user.name + '.') logging.info(str(datetime.datetime.now()) + ' Bot logged in as ' + client.user.name + '.')
print(functions.console.info('Bot logged in as ' + client.user.name + '.')) print(functions.console.info('Bot logged in as ' + client.user.name + '.'))
print('Guilds: ' + str(client.user.guilds))
print('') print('')
print('Log (Consolebased)') print('Log (Consolebased)')
print('------------------') print('------------------')
@ -79,7 +90,7 @@ class Bot(discord.Client):
await asyncio.sleep(10) await asyncio.sleep(10)
async def on_resumed(self): async def on_resumed(self):
logging.info(str(datetime.datetime.now().strftime('%d.%m.%Y %T')) + ' -- Bot resumed seesion.') logging.info(str(datetime.datetime.now().strftime('%d.%m.%Y %T')) + ' -- Bot resumed session.')
print(functions.console.log('Bot resumed a session.')) print(functions.console.log('Bot resumed a session.'))
async def on_interaction(self, interaction): async def on_interaction(self, interaction):
@ -260,5 +271,8 @@ class Bot(discord.Client):
await error('Bot disconected from discord.') await error('Bot disconected from discord.')
#Run #Run
try:
client = Bot(intents = intents, max_messages=None) client = Bot(intents = intents, max_messages=None)
client.run(token, log_handler=None) client.run(token, log_handler=None)
except Exception as e:
print(functions.console.error('Error while trying to connect to discord.\n' + str(e)))