Back to Llama Index

Discord Reader

docs/examples/data_connectors/DiscordDemo.ipynb

0.14.211.5 KB
Original Source

<a href="https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/data_connectors/DiscordDemo.ipynb" target="_parent"></a>

Discord Reader

Demonstrates our Discord data connector

If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.

python
%pip install llama-index-readers-discord
python
!pip install llama-index
python
import logging
import sys

logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
python
# This is due to the fact that we use asyncio.loop_until_complete in
# the DiscordReader. Since the Jupyter kernel itself runs on
# an event loop, we need to add some help with nesting
!pip install nest_asyncio
import nest_asyncio

nest_asyncio.apply()
python
from llama_index.core import SummaryIndex
from llama_index.readers.discord import DiscordReader
from IPython.display import Markdown, display
import os
python
discord_token = os.getenv("DISCORD_TOKEN")
channel_ids = [1057178784895348746]  # Replace with your channel_id
documents = DiscordReader(discord_token=discord_token).load_data(
    channel_ids=channel_ids
)
python
index = SummaryIndex.from_documents(documents)
python
# set Logging to DEBUG for more detailed outputs
query_engine = index.as_query_engine()
response = query_engine.query("<query_text>")
python
display(Markdown(f"<b>{response}</b>"))