Skip to content

Commit

Permalink
bot crash handle
Browse files Browse the repository at this point in the history
  • Loading branch information
Drago-03 committed Dec 2, 2024
1 parent c37ee95 commit e806862
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 41 deletions.
14 changes: 1 addition & 13 deletions cogs/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
from discord.ext import commands
from discord import app_commands
from discord.ui import Select, View
import json

from config import INSTALL_URL, SUPPORT_SERVER_LINK, BOT_WEBSITE
from config import SUPPORT_SERVER_LINK

class HelpDropdown(Select):
def __init__(self, bot):
Expand Down Expand Up @@ -65,17 +64,6 @@ class Help(commands.Cog):
def __init__(self, bot):
self.bot = bot

async def is_premium(self, user_id):
# Check if the user has a premium subscription
try:
with open('premium_users.json', 'r') as f:
premium_users = json.load(f)
if user_id in premium_users:
return premium_users[user_id]['tier']
except FileNotFoundError:
return None
return None

@commands.command(name="help")
async def help_command(self, ctx):
"""Show help information with a dropdown menu"""
Expand Down
45 changes: 17 additions & 28 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,25 @@ async def setup_hook(self):
logger.error(traceback.format_exc())

async def on_ready(self):
logger.info(f'{self.user} has connected to Discord!')
await self.change_presence(
activity=discord.Activity(
type=discord.ActivityType.watching,
name="for .help | /help"
)
)
logger.info(f"Logged in as {self.user} (ID: {self.user.id})")
logger.info("------")

bot = IndieGOBot()
async def on_command_error(self, ctx, error):
if hasattr(ctx.command, 'on_error'):
return

cog = ctx.cog
if cog:
if commands.Cog._get_overridden_method(cog.cog_command_error) is not None:
return

@bot.event
async def on_error(event, *args, **kwargs):
logger.error(f'Error in event {event}:')
logger.error(traceback.format_exc())
logger.error('Ignoring exception in command {}:'.format(ctx.command), exc_info=error)
traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr)

bot = IndieGOBot()

async def main():
try:
logger.info('Starting bot...')
async with bot:
await bot.start(TOKEN)
except Exception as e:
logger.error(f'Fatal error in main: {str(e)}')
logger.error(traceback.format_exc())
sys.exit(1)
async with bot:
await bot.start(TOKEN)

if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
logger.info('Bot shutdown initiated by user')
except Exception as e:
logger.error(f'Unexpected error in runner: {str(e)}')
logger.error(traceback.format_exc())
asyncio.run(main())

0 comments on commit e806862

Please sign in to comment.