Notion-DiscordBot
A discord bot consuming Notion API to add and retrieve data from Notion databases.
Instructions to use the bot:
Pre-Requisites:
a)Install all the requirements using pip3 install -r requirements.txt
b)Create a discord bot using the developer platform of discord and obtain your OAuth2 token. Keep it somewhere safe
c)Go to Notion and create a new Integration https://www.notion.so/my-integrations Note the internal Integration.
d)Go to Notion and create a table like this:
4 columns where:
- Contributor is of property type Title
- URL of url type
- Title of text type
- Tag of multi-select type
e)Click on the three dots and press Open as page
f)Then press share and copy the URL. The URL will look something like this: https://www.notion.so/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX?v=YYYYYYYYYYYYYYYYYYYYYYYYY
Note down the X part of the url (RED part)
This is your database id
g)Also press share again, press Invite and then click on the integration you made earlier
f)Now on the terminal of your machine:
$export DATABASE_TOKEN=<THE DATABASE TOKEN YOU NOTED DOWN>
$export AUTH_KEY=<THE INTEGRATION SECRET KEY FROM NOTION>
$export DISCORD_AUTH=<THE SECRET TOKEN OF BOT>
If you want your prefix to be something else other than '/' then $export PREFIX=<Your Desired character>
Running Procedure:
a)Now simply go into the Bot folder and run: $python3 bot.py
b)On the discord developer site copy the OAuth2 link and paste it in the browser and invite it to a server you own/have permissions to do so
c)Bot Usage:
Adding Record:
/add <URL_YOU_WANT_TO_RECORD>
=> This will add a new record to your database with a misc
tag
/add <URL_YOU_WANT_TO_RECORD> <TAG>
=> This will add a new record to your database with the <TAG>
tag
For multiple tags:
/add <URL_YOU_WANT_TO_RECORD> <TAG>,<TAG1>,<TAG2>
Example:
Sample database populated by the bot:
Searching Record through tags:
/search <Tag1>
For multiple tags: /search <Tag1> <Tag2>.....<TagN>
Deleting Record through tags:
/delete <Tag 1>
For multiple tags: /delete <Tag 1> <Tag2>......<Tag N>
Instead of running the discord bot via python and exporting environment variables you can use our docker container.