initial discord bot setup

This commit is contained in:
skillet 2023-01-27 14:49:55 -05:00
parent a35755592c
commit 12f9db0857
2 changed files with 22 additions and 6 deletions

View File

@ -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()

View File

@ -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()