DEV Community

Cover image for Our team procrastinated on writing bug reports. So we built an AI to do it for us
Suhana Jabin
Suhana Jabin

Posted on

Our team procrastinated on writing bug reports. So we built an AI to do it for us

1. Case Study : AI for creating Bug Reports

Team Problem:

Keeping track of multiple messages in a team can be quite difficult. Discord, a popular platform for team discussions, can soon become overwhelmed with lengthy conversations, making it difficult to find important messages and at times, you can even forget those discussed points .

Team Solution:

What if there was a way to automatically summarize these messages and convert them into actionable insights?

In this article, we will explore a basic approach to do that—using Python to scrape Discord messages, harnessing the summarization power of Google Gemini (a powerful tool that uses Machine learning models for text generation) , and effortlessly integrating these summaries into GitLab as issues. This process not only saves time but also ensures that your team's most important discussions are efficiently tracked and managed.

How it works

Our approach:

  1. Fetching the discord message chunks from the server.
  2. Summarizing it with the help of Gemini
  3. Creating an issue in the Gitlab repo that contains the summary of selected discord issue.

Let's take a quick look on how to implement this idea:
The whole task is divided into 3 basic sections:

Watch Discord

We are utilizing Discord APIs to helps us gather messages from a Discord channel, so we can later process and summarize them using tools like Gemini. This way, we can quickly organize and make sense of large amounts of information.

We need to create a Bot to get the messages from Discord Channel .
So , let's start by creating a Bot in a new application.

a) Creating a new application

  • Login to Discord
  • Navigate to the application page
    Screenshot from 2024-08-17 20-09-40

  • Click on the "New Application" Button on the top right corner.
    Screenshot from 2024-08-17 15-13-50

  • Give the application name and create.
    Screenshot from 2024-08-17 15-03-44

b) Setting up your Bot

  • Navigate to the Bot tab in application page
    Screenshot from 2024-08-18 21-02-52

  • Provide the username and note the Bot Access Token as we need it in the future for connecting this Bot to the respective discord channel.

  • If in case you can't see the Bot Access Token , click the Reset Token to generate a new Bot Access Token.
    Screenshot from 2024-08-17 20-14-06

  • If you want others to invite your Bot to any servers, make sure the public bot is ticked.
    Screenshot from 2024-08-17 20-14-40

Make sure message content intent is ticked to enable your bot to receive messages.
Screenshot from 2024-08-17 20-15-14

Great! So now you have successfully set up your Bot account.

c) Inviting your Bot into your server

  • Head to the Oauth2 tab and navigate to the OAuth2 URL Generator section.
    Screenshot from 2024-08-17 20-18-07

  • Click the Bot checkbox and Bot permission section will appear.
    Screenshot from 2024-08-17 20-18-22

  • Upon clicking the bot checkbox, there will be another box for providing Bot permissions. Choose the permissions as per your usecase. Be careful when you provide the administrator permission to the bot.
    Screenshot from 2024-08-17 20-19-31

  • You can see a link will appear in the generated URL section.
    Screenshot from 2024-08-17 20-22-46

  • Open that url in a new tab and you'll be prompted to select the server.

  • After you select the server, click authorize and you're done with the Bot creation part!
    Screenshot from 2024-08-17 20-26-01

d) The Coding part!

We need to create a Python script to scrap the discord messages in the specific channel.

i) Make sure you have the right permissions

  • We need the channel ID for scraping and it can only be obtained when you're granted administrator privilege.

ii) Install the required libraries

pip install discord
Enter fullscreen mode Exit fullscreen mode

iii) Provide the Bot Access Token

bot_token = **os.getenv('DISCORD_BOT_TOKEN')
Enter fullscreen mode Exit fullscreen mode
  • Bot Access Token is necessary to run the client.

iv) Giving the right permission to the client

intents = discord.Intents.default()

  • Discord Intents are a way of telling which events your bot wants to receive.
  • This line creates an Intent object with default settings and by default, the bot will receive a minimal set of events- messages,reactions and basic events.

v) Enabling the message intent

intents.messages = True

  • This line allows the bot to receive events related to messages.

vi) Configuring Bot Client

client = discord.Client(intents=intents)

  • This line configures the bot client with the right event permissions.

vii) Defining an event handler in Python


async def on_ready():
    print(f'Logged in as {client.user}')
    guild = discord.utils.get(client.guilds)  # Get the first guild (server) the bot is in
    if guild:
        print(f'Connected to guild: {guild.name}')
        for channel in guild.channels:
            print(f'Channel: {channel.name} (ID: {channel.id})')
    else:
        print('No guilds found.')

    channel = client.get_channel(channel_id)
    if channel:
        async for message in channel.history(limit=100):
            print(f'{message.author}: {message.content}')
    else:
        print('Channel not found.')
Enter fullscreen mode Exit fullscreen mode
  • Firstly, the client retrieves the first guild/server it is connected to.
  • Secondly, it checks for the channel with the given channel ID among the list of channels, and if it matches, the client starts an asynchronous loop to fetch the last 100 messages.

To read the rest of the article, visit : https://journal.hexmos.com/bug-description-generator/

Top comments (0)