diff options
author | Joe Robinson <joe@lc8n.com> | 2021-11-25 03:25:44 +0000 |
---|---|---|
committer | Joe Robinson <joe@lc8n.com> | 2021-11-25 03:25:44 +0000 |
commit | 439022f058cb2b9bbf6e2b46c067f4c828a1cab0 (patch) | |
tree | e1f40f477d3bb3597f52250541326885f9dbfdf8 /bot.py |
Initial commit
Diffstat (limited to 'bot.py')
-rw-r--r-- | bot.py | 57 |
1 files changed, 57 insertions, 0 deletions
@@ -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"]) |