From 3978b447932edeed89b3050176f356314a0eb12d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sk=C3=BDpala?= Date: Sun, 26 Mar 2023 14:13:36 +0200 Subject: [PATCH] Some basic structure --- .gitignore | 1 + cogs/basic.py | 17 +++++++++++++++++ data.py | 12 ++++++++++++ main.py | 15 +++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 .gitignore create mode 100644 cogs/basic.py create mode 100644 data.py create mode 100644 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d344ba6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +config.json diff --git a/cogs/basic.py b/cogs/basic.py new file mode 100644 index 0000000..2cef409 --- /dev/null +++ b/cogs/basic.py @@ -0,0 +1,17 @@ +import discord +from discord.ext import commands + +class Basic(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @discord.slash_command() + async def sayhello(self, ctx): + await ctx.respond('Hello world!') + + @discord.slash_command() + async def ping(self, ctx): + await ctx.respond('My ping is {:.0f}ms'.format(self.bot.latency*1000), ephemeral=True) + +def setup(bot): + bot.add_cog(Basic(bot)) diff --git a/data.py b/data.py new file mode 100644 index 0000000..371893a --- /dev/null +++ b/data.py @@ -0,0 +1,12 @@ +import json +import os.path + +DATA_FOLDER = "data" + +def load_json(filename: str): + with open(filename + ".json") as f: + content = json.load(f) + return content + +def load_data(filename: str): + return load_json(os.path.join(DATA_FOLDER, filename)) diff --git a/main.py b/main.py new file mode 100644 index 0000000..761c80a --- /dev/null +++ b/main.py @@ -0,0 +1,15 @@ +from discord.ext import commands +import data + +CONFIG = data.load_json("config") + +bot = commands.Bot() + +cogs_list = [ + 'basic', +] + +for cog in cogs_list: + bot.load_extension(f'cogs.{cog}') + +bot.run(CONFIG["token"])