First Commit
This commit is contained in:
Executable
+71
@@ -0,0 +1,71 @@
|
||||
# main.py
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from web.app import app
|
||||
import threading
|
||||
|
||||
|
||||
def run_web():
|
||||
app.run(debug=False, host="0.0.0.0", port=5000)
|
||||
|
||||
|
||||
class MyNewHelp(commands.MinimalHelpCommand):
|
||||
async def send_pages(self):
|
||||
destination = self.get_destination()
|
||||
for page in self.paginator.pages:
|
||||
emby = discord.Embed(description=page)
|
||||
await destination.send(embed=emby)
|
||||
|
||||
|
||||
class Client(commands.Bot):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
command_prefix=["pY ", "PY ", "Py ", "py "],
|
||||
strip_after_prefix=True,
|
||||
case_insensitive=True,
|
||||
intents=discord.Intents.all(),
|
||||
help_command=MyNewHelp(),
|
||||
)
|
||||
# Set your development guild ID here (as an integer)
|
||||
self.allowed_guild_id = 1381708059600097403 # PLEX
|
||||
self.add_check(self.guild_check)
|
||||
|
||||
async def setup_hook(self): # overwriting a handler
|
||||
cogs_folder = f"{os.path.abspath(os.path.dirname(__file__))}/implementing"
|
||||
for filename in os.listdir(cogs_folder):
|
||||
if filename.endswith(".py"):
|
||||
try:
|
||||
await self.load_extension(f"implementing.{filename[:-3]}")
|
||||
except Exception as e:
|
||||
print(f"Failed to load {filename}: {e}")
|
||||
await self.tree.sync()
|
||||
print("Loaded cogs")
|
||||
|
||||
async def on_message(self, message):
|
||||
# Ignore messages from bots
|
||||
if message.author.bot:
|
||||
return
|
||||
# Only respond in the allowed guild
|
||||
if message.guild and message.guild.id == self.allowed_guild_id:
|
||||
await self.process_commands(message)
|
||||
# Optionally, ignore DMs or messages from other guilds
|
||||
|
||||
async def guild_check(self, ctx):
|
||||
return ctx.guild and ctx.guild.id == self.allowed_guild_id
|
||||
|
||||
|
||||
def main():
|
||||
load_dotenv()
|
||||
client = Client()
|
||||
token = os.getenv("TOKEN")
|
||||
if token is not None:
|
||||
threading.Thread(target=run_web, daemon=True).start()
|
||||
client.run(token)
|
||||
else:
|
||||
print("Token is missing.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user