From 439022f058cb2b9bbf6e2b46c067f4c828a1cab0 Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Thu, 25 Nov 2021 03:25:44 +0000 Subject: Initial commit --- bot.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 bot.py (limited to 'bot.py') diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..4d828b4 --- /dev/null +++ b/bot.py @@ -0,0 +1,57 @@ +import discord +import yaml +import datetime +from discord_slash import SlashContext, SlashCommand +from discord.ext.commands import Bot +from models.user import User + + +with open("config.yaml", "r") as yamlfile: + config = yaml.load(yamlfile, Loader=yaml.CLoader) + print("Read config successful") + config = config + + +intents = discord.Intents.default() +intents.members = True + +bot = Bot(command_prefix="!", self_bot=True, intents=intents) + +slash = SlashCommand(bot, sync_commands=True) + + +# Runs once bot has connected to discord +@bot.event +async def on_ready(): + time_now = datetime.datetime.utcnow() + print(f"{time_now}: {bot.user} has connected to Discord!") + + for guild in bot.guilds: + if guild.id == config["discord_server_id"]: + print(f"{time_now}: {bot.user} has joined {guild.name}!") + for channel in guild.channels: + if channel.name == config["discord_channel"]: + print(f"{time_now}: Found channel {channel.name}!") + + +@bot.event +async def on_message(message): + print(message.author.id) + user = User.get(User.discord_id == message.author.id) + user.add_message() + print(user.display_name) + + +@slash.slash( + name="test", + description="This is just a test command, nothing more.", + guild_ids=[config["discord_server_id"]], +) +async def test(ctx: SlashContext): + print("test") + await ctx.send(content="Beep boop") + + +bot.load_extension("commands.economy") +bot.load_extension("commands.basic_games") +bot.run(config["discord_token"]) -- cgit v1.2.3