Skip to content

Instantly share code, notes, and snippets.

@harsh183
Created October 7, 2021 18:05
Show Gist options
  • Select an option

  • Save harsh183/46ad6e694c8f32ae694e5fc7a8acadd2 to your computer and use it in GitHub Desktop.

Select an option

Save harsh183/46ad6e694c8f32ae694e5fc7a8acadd2 to your computer and use it in GitHub Desktop.
DRES chatbot for looking up resources. Powered by google and discord.py
from discord.ext import commands
from googlesearch import search
bot = commands.Bot(command_prefix='!')
@bot.command(name="uiuc", help="Find a UIUC specific resources")
async def uiuc(ctx, *, question):
# breakpoint()
search_text = f"UIUC {question}"
await ctx.send("You've come to the right place for help! :slight_smile:")
possible_links = search(search_text, num_results=1) # the num results isn't the array length for reasons
unique_links = set(possible_links)
await ctx.send("I looked around and I found a few links that might be a good starting point :thinking:")
for link in unique_links:
await ctx.send(link)
with open("BOT_TOKEN.txt", "r") as token_file:
TOKEN = token_file.read()
print("Token file read")
bot.run(TOKEN)
discord.py
googlesearch-python
@harsh183
Copy link
Author

harsh183 commented Oct 7, 2021

MIT License

Setup

Assuming working python

  1. Create a discord bot and put the token in a file called BOT_TOKEN.txt
  2. To setup pip install -r requirements.txt
  3. python bot.py

@harsh183
Copy link
Author

harsh183 commented Oct 7, 2021

image

image

^In action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment