Discord+Notion Bot

Table of contents


Discord is a modern partyhouse

Discord is the modern party house.

It is essential to be updated with the latest trends. As COVID-19 hit social life badly, the majority population switched to Discord servers to interact and have fun. As we had created our server, we felt the need to have our own specialized bots so that it adds value to the server.

In case you weren’t aware, robots have taken over. Having chatbots run your Discord servers is incredible since you can focus on what’s important. Keeping this in mind and taking into consideration our daily usage of Notion for managing resources and making notes, we thought of creating a discord bot that consumes Notion API to add and retrieve data from Notion databases.

Start building with the Notion API
Connect Notion pages and databases to the tools you use every day, creating powerful workflows. Get started Aggregate…
developers.notion.com.


Now, how to use this bot?

Pre-Requisites:

a) Install all the requirements using pip3 install -r requirements.txtb) 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:

Table

Add the following 4 columns :

  • 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 a page.

Opening the notion.so file.

f) Then press share and copy the URL. The URL will look something like this: https://www.notion.so/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX?v=YYYYYYYYYYYYYYYYYYYYYYYYY

Extracting from the link

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.
h) Google Drive setup: All physical files or PDF files from links are downloaded on a google drive folder of your choice.

Setup Procedure:
a) Follow the README file located in the GitHub repo.
b) Move the credentials.json file and token.json to the creds folder in the Bot folder.
c) Now go to google drive and create a folder. The link to the folder will be something like this https://drive.google.com/drive/folders/ID.
d
) Note the ID down. This will be the id of the folder where all files will be stored. Also, share the folder accordingly.
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 GDRIVE_FOLDER=<FOLDER ID YOU NOTED ABOVE> $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 into the browser and invite it to a server you own/have permission to do so. c) Bot Usage: *Adding Record: */add =&gt; This will add a new record to your database with amisctag./add =&gt; This will add a new record to your database with the` tag.

For multiple tags: /add <URL_YOU_WANT_TO_RECORD> <TAG>,<TAG1>,<TAG2>

Example

Sample database populated by the bot

Searching records through tags:

/search <Tag1>For multiple tags: /search <Tag1> <Tag2>.....<TagN>

Example (1)

Example (2)

Deleting records through tags:

/delete <Tag 1>For multiple tags: /delete <Tag 1> <Tag2>......<Tag N>

Example:

Initial Database

Deleting the record

Final Database

Uploading Files:

NOTE: In the below images, the prefix used is: !

You can upload any file to the notion database. It can be a PDF, PNG, JPEG, etc.
In the example below, a PNG file is being uploaded.
a) Drag your file to the chat in discord.

b) Add a comment to the file you uploaded.

Here memoji and profile-pic are tags for the file

c) It will then ask for the title of the file you uploaded.

d) Now, the file will be uploaded to the google drive folder which you mentioned above.
e) The database will be updated.

The link will open the file in Google Drive.


If your team is using Discord and looking for a database management bot, Notion bot is here for you! You can access all the open source repositories of this bot on GitHub and docker-hub and, in fact, invite it to your server as well since it is verified by Discord. That’s pretty amazing, right?

The above example is fulfilled by accessing our GitHub repository:
https://github.com/Servatom/Notion-DiscordBot

Instead of running the discord bot via python and exporting environment variables, you can use our docker image.
https://hub.docker.com/repository/docker/servatom/notiondiscordbot

Did you find this article valuable?

Support Adamay Mann by becoming a sponsor. Any amount is appreciated!