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