<gh_stars>0
import discord
import logging
import json
import os
from discord.ext import commands


with open('Token.json', mode='r', encoding='utf-8') as t:
    data = t.read()
    token = json.loads(data)

logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler(filename='registro.log',
                              encoding='utf-8', mode='w')
handler.setFormatter(logging.Formatter('%(asctime)s: %(levelname)s:'
                                       '%(name)s: %(message)s'))
logger.addHandler(handler)

intents = discord.Intents.all()

bot = commands.Bot(command_prefix='q.' 'Q.', intents=intents)


for filename in os.listdir('./cogs'):
    if filename.endswith('.py'):
        bot.load_extension(f'cogs.{filename[:-3]}')


@bot.event
async def on_ready():
    print(f'conectado como {bot.user}')
    await bot.change_presence(activity=discord.Activity(
        type=discord.ActivityType.playing, name='Cosas de robots'))


@bot.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.CommandNotFound):
        await ctx.send('Ese comando no existe.')
    else:
        await ctx.send('Ha ocurrido un error.')

bot.run(token['token'])
