diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..78f6ca0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.env +venv +.DS_Store +.vscode +__pycache__ +node_modules diff --git a/python/discord.py/subclassed-bot/.env.example b/python/discord.py/subclassed-bot/.env.example new file mode 100644 index 0000000..3cbac21 --- /dev/null +++ b/python/discord.py/subclassed-bot/.env.example @@ -0,0 +1 @@ +TOKEN=your-bot-token diff --git a/python/discord.py/subclassed-bot/__main__.py b/python/discord.py/subclassed-bot/__main__.py new file mode 100644 index 0000000..bf3d72a --- /dev/null +++ b/python/discord.py/subclassed-bot/__main__.py @@ -0,0 +1,6 @@ +from bot import BadBot + +trashest_bot_ever = BadBot() # dont pass in things here, pass in ./bot.py + +if __name__ == "__main__": + trashest_bot_ever.run() diff --git a/python/discord.py/subclassed-bot/__pycache__/bot.cpython-39.pyc b/python/discord.py/subclassed-bot/__pycache__/bot.cpython-39.pyc new file mode 100644 index 0000000..a69c72c Binary files /dev/null and b/python/discord.py/subclassed-bot/__pycache__/bot.cpython-39.pyc differ diff --git a/python/discord.py/subclassed-bot/bot.py b/python/discord.py/subclassed-bot/bot.py new file mode 100644 index 0000000..4c88a49 --- /dev/null +++ b/python/discord.py/subclassed-bot/bot.py @@ -0,0 +1,71 @@ +import os + +from dotenv import load_dotenv + +import discord +from discord.ext import commands + +load_dotenv() + +intents = discord.Intents.all() +intents.presences = False + +# Define the actual subclassed bot inheriting from commands.Bot or commands.AutoShardedBot +class BadBot(commands.Bot): # use commands.AutoShardedBot if you want to shard the bot + def __init__(self, *args, **kwargs): + # initialising the super class + super().__init__( + command_prefix=self._get_bot_prefix, # The get prefix function + owner_id=711444754080071714, # fill this with your ID + # owner_ids=[your_moms_id, your_dads_id] # use this if there are multiple owners, + intents=intents, # customise it accordingly, I prefer not to use presence intents, they have no use for me + allowed_mentions=discord.AllowedMentions( + everyone=False, roles=False, users=True, replied_user=False + ), # customise it accordingly again :) + description="This is a bad bot, by Donut#4427 who doesn't even know how to code", # the bot's description + case_insensitive=True, # case insensitivity + strip_after_prefix=True, # Whether to strip whitespace characters after encountering the command prefix + *args, # obvious + **kwargs, # obvious + ) + self.secrets = { + x: y + for x, y in os.environ.items() + if x in ["TOKEN"] # add more to these keys accordingly + } # Our secrets keys kept as a dictionary + self.bot_cogs = [ + f"cogs.{cog[:-3]}" + for cog in os.listdir("cogs") + if cog.endswith(".py") + and not cog.startswith( + "_" + ) # files not starting with _ and ending with .py will be considered + ] # if you use cogs ¯\_(ツ)_/¯ + + def run(self): + try: + for cog in self.bot_cogs: # loading all the cogs + try: + self.load_extension(cog) + print(f"Loaded {cog[5:]}") + except: + raise + except: + raise + super().run(self.secrets["TOKEN"]) # Running the bot :) + + async def _get_bot_prefix(self, bot, message): + prefixes = ["!", "?"] # do db stuff here, imma keep it static + base = [f"<@!{bot.user.id}> ", f"<@{bot.user.id}> "] # mention prefixes + return [*prefixes, *base] + + async def on_ready(self): # on_ready event + print(f"Logged in as {self.user}.") + + async def process_commands( + self, message + ): # https://discordpy.readthedocs.io/en/master/ext/commands/api.html#discord.ext.commands.Bot.process_commands + if not message.guild or message.author.bot: + return + + await super().process_commands(message) diff --git a/python/discord.py/subclassed-bot/cogs/__pycache__/handlers.cpython-39.pyc b/python/discord.py/subclassed-bot/cogs/__pycache__/handlers.cpython-39.pyc new file mode 100644 index 0000000..e8703da Binary files /dev/null and b/python/discord.py/subclassed-bot/cogs/__pycache__/handlers.cpython-39.pyc differ diff --git a/python/discord.py/subclassed-bot/cogs/handlers.py b/python/discord.py/subclassed-bot/cogs/handlers.py new file mode 100644 index 0000000..3812467 --- /dev/null +++ b/python/discord.py/subclassed-bot/cogs/handlers.py @@ -0,0 +1,11 @@ +from discord.ext import commands + + +# Just a testing cog +class Handlers(commands.Cog): + def __init__(self, trashest_bot_ever): + self.trashest_bot_ever = trashest_bot_ever + + +def setup(trashest_bot_ever): + trashest_bot_ever.add_cog(Handlers(trashest_bot_ever)) diff --git a/python/discord.py/subclassed-bot/requirements.txt b/python/discord.py/subclassed-bot/requirements.txt new file mode 100644 index 0000000..79271e7 --- /dev/null +++ b/python/discord.py/subclassed-bot/requirements.txt @@ -0,0 +1 @@ +discord.py>=1.7.0