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 import os
from sys import stderr
import discord import discord
@ -6,14 +7,12 @@ import discord
def init(): def init():
# make sure this prints the discord token # make sure this prints the discord token
# set this up as a runtime environment variable, DO NOT HARDCODE THE TOKEN # set this up as a runtime environment variable, DO NOT HARDCODE THE TOKEN
try: distoken = os.environ.get("DISCORD_TOKEN")
disToken = os.environ[ if not distoken:
'DISCORD_TOKEN'] # grabs the discord token from the environment variable, if not there, exit print("Unable to find discord token in environment!", file=stderr)
except:
print("ERROR: unable to find discord token in environment variables!")
exit(1) exit(1)
print("discord Token:"+disToken) print(f"discord token:{distoken}")
init() init()

View File

@ -3,6 +3,14 @@ from os import environ
from sys import stderr 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 # main runtime function
def main(): def main():
if disToken := environ.get('DISCORD_TOKEN'): if disToken := environ.get('DISCORD_TOKEN'):
@ -12,5 +20,14 @@ def main():
print("Unable to access DISCORD_TOKEN in environment!", file=stderr) print("Unable to access DISCORD_TOKEN in environment!", file=stderr)
exit(1) 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() main()