Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from discord.ext import commands
- from dotenv import load_dotenv
- import os
- import asyncio
- import tkinter as tk
- from threading import Thread
- load_dotenv()
- DISCORD_DARK = 0x36393F
- DISCORD_GREY = 0x2C2F33
- DISCORD_GREEN = 0x57F287
- DISCORD_RED = 0xED4245
- DISCORD_YELLOW = 0xFEE75C
- initial_extensions = [
- 'cogs.ping',
- 'cogs.whois',
- 'cogs.info',
- 'cogs.help',
- 'cogs.msg',
- 'cogs.rip',
- 'cogs.prefix',
- 'cogs.meme',
- 'cogs.startcod',
- 'cogs.ww2',
- 'cogs.helpsys',
- 'cogs.fanmade_cards',
- ]
- class Bot(commands.Bot):
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.is_running = False
- self.is_ready = False # New attribute to track readiness
- async def on_ready(self):
- self.is_ready = True # Set the readiness flag when the bot is ready
- status_label.config(text="Status: On", fg="green") # Update the status label
- async def start_bot(self):
- TOKEN = os.getenv("DISCORD_TOKEN")
- await self.start(TOKEN)
- async def stop_bot(self):
- await self.close()
- async def run_bot(bot):
- for extension in initial_extensions:
- await bot.load_extension(extension)
- ### Command Not Found
- @bot.event
- async def on_command_error(ctx, error):
- if isinstance(error, commands.CommandNotFound):
- await ctx.send("Command not found. Please enter a valid command.")
- await bot.start_bot()
- def start_bot_thread(bot):
- loop = asyncio.new_event_loop()
- asyncio.set_event_loop(loop)
- try:
- loop.run_until_complete(run_bot(bot))
- finally:
- loop.close()
- def toggle_bot():
- global bot
- if bot.is_running:
- bot.loop.call_soon_threadsafe(bot.loop.create_task, bot.stop_bot())
- bot.loop.call_soon_threadsafe(bot.loop.stop)
- bot.loop.call_soon_threadsafe(bot.loop.close)
- bot.is_running = False
- status_label.config(text="Status: Off", fg=f"#{DISCORD_RED:06X}")
- start_stop_button.config(text="Start DEclipse", bg=f"#{DISCORD_GREEN:06X}")
- else:
- bot_thread = Thread(target=start_bot_thread, args=(bot,))
- bot_thread.start()
- bot.is_running = True
- status_label.config(text="Status: Connecting", fg=f"#{DISCORD_YELLOW:06X}")
- start_stop_button.config(text="Stop DEclipse", bg=f"#{DISCORD_RED:06X}")
- bot = Bot(command_prefix='!', self_bot=True, help_command=None)
- root = tk.Tk()
- root.title("DEclipse")
- root.geometry("500x300")
- root.configure(bg=f"#{DISCORD_DARK:06X}")
- start_stop_button = tk.Button(root, text="Start DEclipse", command=toggle_bot, bg=f"#{DISCORD_GREEN:06X}")
- start_stop_button.pack(pady=20)
- status_label = tk.Label(root, text="Status: Off", fg=f"#{DISCORD_RED:06X}", bg=f"#{DISCORD_DARK:06X}")
- status_label.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement