mirror of
https://github.com/AsgardEternal/DiscordWhitelist.git
synced 2024-12-28 22:29:13 -06:00
initial discord bot setup
This commit is contained in:
parent
a35755592c
commit
12f9db0857
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user