-
Notifications
You must be signed in to change notification settings - Fork 0
/
noni.py
49 lines (39 loc) · 1.13 KB
/
noni.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import discord
from discord.ext import commands
import os
from dotenv import load_dotenv
import json
# Loads .env file if it exists
load_dotenv()
# Pulls token from said .env file
TOKEN = os.getenv("DISCORD_TOKEN")
with open('config.json') as f:
data = json.load(f)
prefix = data["PREFIX"]
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_ready():
print(f'Logged in as {client.user}')
print('Bot is online!')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
# Checks for existing .env with bot token
try:
f = open('.env')
f.close()
# If .env doesn't exist, asks user for token
except FileNotFoundError:
TOKEN = input("Paste your bot's token: ")
# If user saves token, .env is created and ignored by git
if input("Remember token? Y/n: ") == "Y" or "y":
open(".env","w+").write(f"DISCORD_TOKEN={TOKEN}")
else:
print("Token not saved.")
# Bot starts
client.run(TOKEN)