From 12f9db08576bcffee7069864a0c378e1ede810a3 Mon Sep 17 00:00:00 2001 From: skillet Date: Fri, 27 Jan 2023 14:49:55 -0500 Subject: [PATCH] initial discord bot setup --- autowl/__init__.py | 11 +++++------ autowl/__main__.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/autowl/__init__.py b/autowl/__init__.py index 5680cd7..c66de6c 100644 --- a/autowl/__init__.py +++ b/autowl/__init__.py @@ -1,4 +1,5 @@ import os +from sys import stderr import discord @@ -6,14 +7,12 @@ import discord def init(): # make sure this prints the discord token # set this up as a runtime environment variable, DO NOT HARDCODE THE TOKEN - try: - disToken = os.environ[ - 'DISCORD_TOKEN'] # grabs the discord token from the environment variable, if not there, exit - except: - print("ERROR: unable to find discord token in environment variables!") + distoken = os.environ.get("DISCORD_TOKEN") + if not distoken: + print("Unable to find discord token in environment!", file=stderr) exit(1) - print("discord Token:"+disToken) + print(f"discord token:{distoken}") init() diff --git a/autowl/__main__.py b/autowl/__main__.py index b597726..14da003 100644 --- a/autowl/__main__.py +++ b/autowl/__main__.py @@ -3,6 +3,14 @@ from os import environ from sys import stderr +class WhiteLister(discord.Client): + async def on_ready(self): + print(f"Logged on as {self.user}") + + async def on_message(self, message): + print(f"Message from {message.author}: {message.content}") + + # main runtime function def main(): if disToken := environ.get('DISCORD_TOKEN'): @@ -12,5 +20,14 @@ def main(): print("Unable to access DISCORD_TOKEN in environment!", file=stderr) exit(1) + intents = discord.Intents.default() + intents.message_content = True + + client = WhiteLister(intents=intents) + try: + client.run(disToken) + except: + print("Invalid discord token!", file=stderr) + main()