-
Notifications
You must be signed in to change notification settings - Fork 1
/
RABot.py
41 lines (32 loc) · 1.23 KB
/
RABot.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
import discord
import logging
from discord.ext import commands
import os
from dotenv import load_dotenv
from funcs.IndexRet import qna
from utils.utils import generate_directory_structure
# Load environment variables from .env file
load_dotenv()
DISCORD_BOT_TOKEN = os.getenv("DISCORD_BOT_TOKEN")
COURSES = [x[0] for x in generate_directory_structure('./storage')]
client = discord.Client(intents=discord.Intents.default())
# handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
#check if the author of the message is the same as the bot itself.
if message.author == client.user:
return
if message.content.startswith('Hello'):
print(message.content)
await message.channel.send('How can I help you?')
if message.content.startswith('Question:'):
for course in COURSES:
if course in message.content:
print(message.content)
await message.channel.send(qna(course, message.content[16:-23]))
break
# client.run(DISCORD_BOT_TOKEN, log_handler=handler)
client.run(DISCORD_BOT_TOKEN)